database schema adjustments to server/realm/scene
This commit is contained in:
parent
a102c96bb4
commit
09590edd95
79 changed files with 7100 additions and 100 deletions
|
|
@ -19,10 +19,10 @@ pub async fn join_channel<'e>(
|
|||
// Note: channel_id is actually scene_id in this system
|
||||
let member = sqlx::query_as::<_, ChannelMember>(
|
||||
r#"
|
||||
INSERT INTO realm.channel_members (channel_id, user_id, position)
|
||||
INSERT INTO scene.instance_members (instance_id, user_id, position)
|
||||
SELECT $1, $2, COALESCE(
|
||||
-- Try to restore last position if user was in the same scene
|
||||
-- Note: channel_id = scene_id in this system
|
||||
-- Note: instance_id = scene_id in this system
|
||||
(SELECT m.last_position
|
||||
FROM realm.memberships m
|
||||
JOIN realm.scenes s ON s.id = $1
|
||||
|
|
@ -33,11 +33,11 @@ pub async fn join_channel<'e>(
|
|||
-- Default position
|
||||
ST_SetSRID(ST_MakePoint(400, 300), 0)
|
||||
)
|
||||
ON CONFLICT (channel_id, user_id) DO UPDATE
|
||||
ON CONFLICT (instance_id, user_id) DO UPDATE
|
||||
SET joined_at = now()
|
||||
RETURNING
|
||||
id,
|
||||
channel_id,
|
||||
instance_id as channel_id,
|
||||
user_id,
|
||||
guest_session_id,
|
||||
ST_X(position) as position_x,
|
||||
|
|
@ -66,9 +66,9 @@ pub async fn ensure_active_avatar<'e>(
|
|||
) -> Result<(), AppError> {
|
||||
sqlx::query(
|
||||
r#"
|
||||
INSERT INTO props.active_avatars (user_id, realm_id, avatar_id, current_emotion)
|
||||
INSERT INTO auth.active_avatars (user_id, realm_id, avatar_id, current_emotion)
|
||||
SELECT $1, $2, id, 0
|
||||
FROM props.avatars
|
||||
FROM auth.avatars
|
||||
WHERE user_id = $1 AND slot_number = 0
|
||||
ON CONFLICT (user_id, realm_id) DO NOTHING
|
||||
"#,
|
||||
|
|
@ -95,10 +95,10 @@ pub async fn leave_channel<'e>(
|
|||
sqlx::query(
|
||||
r#"
|
||||
WITH member_info AS (
|
||||
SELECT cm.position, cm.channel_id as scene_id, s.realm_id
|
||||
FROM realm.channel_members cm
|
||||
JOIN realm.scenes s ON cm.channel_id = s.id
|
||||
WHERE cm.channel_id = $1 AND cm.user_id = $2
|
||||
SELECT cm.position, cm.instance_id as scene_id, s.realm_id
|
||||
FROM scene.instance_members cm
|
||||
JOIN realm.scenes s ON cm.instance_id = s.id
|
||||
WHERE cm.instance_id = $1 AND cm.user_id = $2
|
||||
),
|
||||
save_position AS (
|
||||
UPDATE realm.memberships m
|
||||
|
|
@ -110,8 +110,8 @@ pub async fn leave_channel<'e>(
|
|||
RETURNING m.user_id
|
||||
),
|
||||
do_delete AS (
|
||||
DELETE FROM realm.channel_members
|
||||
WHERE channel_id = $1 AND user_id = $2
|
||||
DELETE FROM scene.instance_members
|
||||
WHERE instance_id = $1 AND user_id = $2
|
||||
RETURNING user_id
|
||||
)
|
||||
SELECT COUNT(*) FROM save_position, do_delete
|
||||
|
|
@ -135,11 +135,11 @@ pub async fn update_position<'e>(
|
|||
) -> Result<(), AppError> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
UPDATE realm.channel_members
|
||||
UPDATE scene.instance_members
|
||||
SET position = ST_SetSRID(ST_MakePoint($3, $4), 0),
|
||||
last_moved_at = now(),
|
||||
is_moving = true
|
||||
WHERE channel_id = $1 AND user_id = $2
|
||||
WHERE instance_id = $1 AND user_id = $2
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
|
|
@ -166,7 +166,7 @@ pub async fn get_channel_members<'e>(
|
|||
r#"
|
||||
SELECT
|
||||
cm.id,
|
||||
cm.channel_id,
|
||||
cm.instance_id as channel_id,
|
||||
cm.user_id,
|
||||
cm.guest_session_id,
|
||||
COALESCE(u.display_name, gs.guest_name, 'Anonymous') as display_name,
|
||||
|
|
@ -177,11 +177,11 @@ pub async fn get_channel_members<'e>(
|
|||
cm.is_afk,
|
||||
COALESCE(aa.current_emotion, 0::smallint) as current_emotion,
|
||||
cm.joined_at
|
||||
FROM realm.channel_members cm
|
||||
FROM scene.instance_members cm
|
||||
LEFT JOIN auth.users u ON cm.user_id = u.id
|
||||
LEFT JOIN auth.guest_sessions gs ON cm.guest_session_id = gs.id
|
||||
LEFT JOIN props.active_avatars aa ON cm.user_id = aa.user_id AND aa.realm_id = $2
|
||||
WHERE cm.channel_id = $1
|
||||
LEFT JOIN auth.active_avatars aa ON cm.user_id = aa.user_id AND aa.realm_id = $2
|
||||
WHERE cm.instance_id = $1
|
||||
ORDER BY cm.joined_at ASC
|
||||
"#,
|
||||
)
|
||||
|
|
@ -204,7 +204,7 @@ pub async fn get_channel_member<'e>(
|
|||
r#"
|
||||
SELECT
|
||||
cm.id,
|
||||
cm.channel_id,
|
||||
cm.instance_id as channel_id,
|
||||
cm.user_id,
|
||||
cm.guest_session_id,
|
||||
COALESCE(u.display_name, 'Anonymous') as display_name,
|
||||
|
|
@ -215,10 +215,10 @@ pub async fn get_channel_member<'e>(
|
|||
cm.is_afk,
|
||||
COALESCE(aa.current_emotion, 0::smallint) as current_emotion,
|
||||
cm.joined_at
|
||||
FROM realm.channel_members cm
|
||||
FROM scene.instance_members cm
|
||||
LEFT JOIN auth.users u ON cm.user_id = u.id
|
||||
LEFT JOIN props.active_avatars aa ON cm.user_id = aa.user_id AND aa.realm_id = $3
|
||||
WHERE cm.channel_id = $1 AND cm.user_id = $2
|
||||
LEFT JOIN auth.active_avatars aa ON cm.user_id = aa.user_id AND aa.realm_id = $3
|
||||
WHERE cm.instance_id = $1 AND cm.user_id = $2
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
|
|
@ -238,9 +238,9 @@ pub async fn set_stopped<'e>(
|
|||
) -> Result<(), AppError> {
|
||||
sqlx::query(
|
||||
r#"
|
||||
UPDATE realm.channel_members
|
||||
UPDATE scene.instance_members
|
||||
SET is_moving = false
|
||||
WHERE channel_id = $1 AND user_id = $2
|
||||
WHERE instance_id = $1 AND user_id = $2
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
|
|
@ -260,9 +260,9 @@ pub async fn set_afk<'e>(
|
|||
) -> Result<(), AppError> {
|
||||
sqlx::query(
|
||||
r#"
|
||||
UPDATE realm.channel_members
|
||||
UPDATE scene.instance_members
|
||||
SET is_afk = $3
|
||||
WHERE channel_id = $1 AND user_id = $2
|
||||
WHERE instance_id = $1 AND user_id = $2
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue