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
|
|
@ -17,7 +17,7 @@ pub async fn get_active_avatar<'e>(
|
|||
let avatar = sqlx::query_as::<_, ActiveAvatar>(
|
||||
r#"
|
||||
SELECT user_id, realm_id, avatar_id, current_emotion, updated_at
|
||||
FROM props.active_avatars
|
||||
FROM auth.active_avatars
|
||||
WHERE user_id = $1 AND realm_id = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -60,23 +60,23 @@ pub async fn set_emotion<'e>(
|
|||
let query = format!(
|
||||
r#"
|
||||
WITH updated AS (
|
||||
UPDATE props.active_avatars
|
||||
UPDATE auth.active_avatars
|
||||
SET current_emotion = $3, updated_at = now()
|
||||
WHERE user_id = $1 AND realm_id = $2
|
||||
RETURNING avatar_id
|
||||
)
|
||||
SELECT
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_0) as p0,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_1) as p1,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_2) as p2,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_3) as p3,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_4) as p4,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_5) as p5,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_6) as p6,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_7) as p7,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.{prefix}_8) as p8
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_0) as p0,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_1) as p1,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_2) as p2,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_3) as p3,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_4) as p4,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_5) as p5,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_6) as p6,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_7) as p7,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.{prefix}_8) as p8
|
||||
FROM updated u
|
||||
JOIN props.avatars a ON a.id = u.avatar_id
|
||||
JOIN auth.avatars a ON a.id = u.avatar_id
|
||||
"#,
|
||||
prefix = emotion_prefix
|
||||
);
|
||||
|
|
@ -128,76 +128,76 @@ pub async fn get_emotion_availability<'e>(
|
|||
(a.e_neutral_0 IS NOT NULL OR a.e_neutral_1 IS NOT NULL OR a.e_neutral_2 IS NOT NULL OR
|
||||
a.e_neutral_3 IS NOT NULL OR a.e_neutral_4 IS NOT NULL OR a.e_neutral_5 IS NOT NULL OR
|
||||
a.e_neutral_6 IS NOT NULL OR a.e_neutral_7 IS NOT NULL OR a.e_neutral_8 IS NOT NULL) as avail_0,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_neutral_4) as preview_0,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_neutral_4) as preview_0,
|
||||
|
||||
-- Happy (1)
|
||||
(a.e_happy_0 IS NOT NULL OR a.e_happy_1 IS NOT NULL OR a.e_happy_2 IS NOT NULL OR
|
||||
a.e_happy_3 IS NOT NULL OR a.e_happy_4 IS NOT NULL OR a.e_happy_5 IS NOT NULL OR
|
||||
a.e_happy_6 IS NOT NULL OR a.e_happy_7 IS NOT NULL OR a.e_happy_8 IS NOT NULL) as avail_1,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_happy_4) as preview_1,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_happy_4) as preview_1,
|
||||
|
||||
-- Sad (2)
|
||||
(a.e_sad_0 IS NOT NULL OR a.e_sad_1 IS NOT NULL OR a.e_sad_2 IS NOT NULL OR
|
||||
a.e_sad_3 IS NOT NULL OR a.e_sad_4 IS NOT NULL OR a.e_sad_5 IS NOT NULL OR
|
||||
a.e_sad_6 IS NOT NULL OR a.e_sad_7 IS NOT NULL OR a.e_sad_8 IS NOT NULL) as avail_2,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_sad_4) as preview_2,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_sad_4) as preview_2,
|
||||
|
||||
-- Angry (3)
|
||||
(a.e_angry_0 IS NOT NULL OR a.e_angry_1 IS NOT NULL OR a.e_angry_2 IS NOT NULL OR
|
||||
a.e_angry_3 IS NOT NULL OR a.e_angry_4 IS NOT NULL OR a.e_angry_5 IS NOT NULL OR
|
||||
a.e_angry_6 IS NOT NULL OR a.e_angry_7 IS NOT NULL OR a.e_angry_8 IS NOT NULL) as avail_3,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_angry_4) as preview_3,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_angry_4) as preview_3,
|
||||
|
||||
-- Surprised (4)
|
||||
(a.e_surprised_0 IS NOT NULL OR a.e_surprised_1 IS NOT NULL OR a.e_surprised_2 IS NOT NULL OR
|
||||
a.e_surprised_3 IS NOT NULL OR a.e_surprised_4 IS NOT NULL OR a.e_surprised_5 IS NOT NULL OR
|
||||
a.e_surprised_6 IS NOT NULL OR a.e_surprised_7 IS NOT NULL OR a.e_surprised_8 IS NOT NULL) as avail_4,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_surprised_4) as preview_4,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_surprised_4) as preview_4,
|
||||
|
||||
-- Thinking (5)
|
||||
(a.e_thinking_0 IS NOT NULL OR a.e_thinking_1 IS NOT NULL OR a.e_thinking_2 IS NOT NULL OR
|
||||
a.e_thinking_3 IS NOT NULL OR a.e_thinking_4 IS NOT NULL OR a.e_thinking_5 IS NOT NULL OR
|
||||
a.e_thinking_6 IS NOT NULL OR a.e_thinking_7 IS NOT NULL OR a.e_thinking_8 IS NOT NULL) as avail_5,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_thinking_4) as preview_5,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_thinking_4) as preview_5,
|
||||
|
||||
-- Laughing (6)
|
||||
(a.e_laughing_0 IS NOT NULL OR a.e_laughing_1 IS NOT NULL OR a.e_laughing_2 IS NOT NULL OR
|
||||
a.e_laughing_3 IS NOT NULL OR a.e_laughing_4 IS NOT NULL OR a.e_laughing_5 IS NOT NULL OR
|
||||
a.e_laughing_6 IS NOT NULL OR a.e_laughing_7 IS NOT NULL OR a.e_laughing_8 IS NOT NULL) as avail_6,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_laughing_4) as preview_6,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_laughing_4) as preview_6,
|
||||
|
||||
-- Crying (7)
|
||||
(a.e_crying_0 IS NOT NULL OR a.e_crying_1 IS NOT NULL OR a.e_crying_2 IS NOT NULL OR
|
||||
a.e_crying_3 IS NOT NULL OR a.e_crying_4 IS NOT NULL OR a.e_crying_5 IS NOT NULL OR
|
||||
a.e_crying_6 IS NOT NULL OR a.e_crying_7 IS NOT NULL OR a.e_crying_8 IS NOT NULL) as avail_7,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_crying_4) as preview_7,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_crying_4) as preview_7,
|
||||
|
||||
-- Love (8)
|
||||
(a.e_love_0 IS NOT NULL OR a.e_love_1 IS NOT NULL OR a.e_love_2 IS NOT NULL OR
|
||||
a.e_love_3 IS NOT NULL OR a.e_love_4 IS NOT NULL OR a.e_love_5 IS NOT NULL OR
|
||||
a.e_love_6 IS NOT NULL OR a.e_love_7 IS NOT NULL OR a.e_love_8 IS NOT NULL) as avail_8,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_love_4) as preview_8,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_love_4) as preview_8,
|
||||
|
||||
-- Confused (9)
|
||||
(a.e_confused_0 IS NOT NULL OR a.e_confused_1 IS NOT NULL OR a.e_confused_2 IS NOT NULL OR
|
||||
a.e_confused_3 IS NOT NULL OR a.e_confused_4 IS NOT NULL OR a.e_confused_5 IS NOT NULL OR
|
||||
a.e_confused_6 IS NOT NULL OR a.e_confused_7 IS NOT NULL OR a.e_confused_8 IS NOT NULL) as avail_9,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_confused_4) as preview_9,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_confused_4) as preview_9,
|
||||
|
||||
-- Sleeping (10)
|
||||
(a.e_sleeping_0 IS NOT NULL OR a.e_sleeping_1 IS NOT NULL OR a.e_sleeping_2 IS NOT NULL OR
|
||||
a.e_sleeping_3 IS NOT NULL OR a.e_sleeping_4 IS NOT NULL OR a.e_sleeping_5 IS NOT NULL OR
|
||||
a.e_sleeping_6 IS NOT NULL OR a.e_sleeping_7 IS NOT NULL OR a.e_sleeping_8 IS NOT NULL) as avail_10,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_sleeping_4) as preview_10,
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_sleeping_4) as preview_10,
|
||||
|
||||
-- Wink (11)
|
||||
(a.e_wink_0 IS NOT NULL OR a.e_wink_1 IS NOT NULL OR a.e_wink_2 IS NOT NULL OR
|
||||
a.e_wink_3 IS NOT NULL OR a.e_wink_4 IS NOT NULL OR a.e_wink_5 IS NOT NULL OR
|
||||
a.e_wink_6 IS NOT NULL OR a.e_wink_7 IS NOT NULL OR a.e_wink_8 IS NOT NULL) as avail_11,
|
||||
(SELECT prop_asset_path FROM props.inventory WHERE id = a.e_wink_4) as preview_11
|
||||
(SELECT prop_asset_path FROM auth.inventory WHERE id = a.e_wink_4) as preview_11
|
||||
|
||||
FROM props.active_avatars aa
|
||||
JOIN props.avatars a ON aa.avatar_id = a.id
|
||||
FROM auth.active_avatars aa
|
||||
JOIN auth.avatars a ON aa.avatar_id = a.id
|
||||
WHERE aa.user_id = $1 AND aa.realm_id = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -294,8 +294,8 @@ pub async fn get_avatar_with_paths(
|
|||
SELECT
|
||||
a.*,
|
||||
aa.current_emotion
|
||||
FROM props.active_avatars aa
|
||||
JOIN props.avatars a ON aa.avatar_id = a.id
|
||||
FROM auth.active_avatars aa
|
||||
JOIN auth.avatars a ON aa.avatar_id = a.id
|
||||
WHERE aa.user_id = $1 AND aa.realm_id = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -395,7 +395,7 @@ pub async fn get_avatar_with_paths(
|
|||
HashMap::new()
|
||||
} else {
|
||||
sqlx::query_as::<_, (Uuid, String)>(
|
||||
"SELECT id, prop_asset_path FROM props.inventory WHERE id = ANY($1)",
|
||||
"SELECT id, prop_asset_path FROM auth.inventory WHERE id = ANY($1)",
|
||||
)
|
||||
.bind(&uuids)
|
||||
.fetch_all(pool)
|
||||
|
|
@ -540,8 +540,8 @@ pub async fn get_avatar_with_paths_conn(
|
|||
SELECT
|
||||
a.*,
|
||||
aa.current_emotion
|
||||
FROM props.active_avatars aa
|
||||
JOIN props.avatars a ON aa.avatar_id = a.id
|
||||
FROM auth.active_avatars aa
|
||||
JOIN auth.avatars a ON aa.avatar_id = a.id
|
||||
WHERE aa.user_id = $1 AND aa.realm_id = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -641,7 +641,7 @@ pub async fn get_avatar_with_paths_conn(
|
|||
HashMap::new()
|
||||
} else {
|
||||
sqlx::query_as::<_, (Uuid, String)>(
|
||||
"SELECT id, prop_asset_path FROM props.inventory WHERE id = ANY($1)",
|
||||
"SELECT id, prop_asset_path FROM auth.inventory WHERE id = ANY($1)",
|
||||
)
|
||||
.bind(&uuids)
|
||||
.fetch_all(&mut *conn)
|
||||
|
|
@ -941,7 +941,7 @@ pub async fn set_emotion_simple<'e>(
|
|||
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
UPDATE props.active_avatars
|
||||
UPDATE auth.active_avatars
|
||||
SET current_emotion = $3, updated_at = now()
|
||||
WHERE user_id = $1 AND realm_id = $2
|
||||
"#,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ pub async fn get_channel_info<'e>(
|
|||
let info = sqlx::query_as::<_, ChannelInfo>(
|
||||
r#"
|
||||
SELECT
|
||||
c.id,
|
||||
c.scene_id,
|
||||
i.id,
|
||||
i.scene_id,
|
||||
s.realm_id
|
||||
FROM realm.channels c
|
||||
JOIN realm.scenes s ON s.id = c.scene_id
|
||||
WHERE c.id = $1
|
||||
FROM scene.instances i
|
||||
JOIN realm.scenes s ON s.id = i.scene_id
|
||||
WHERE i.id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(channel_id)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub async fn list_user_inventory<'e>(
|
|||
is_droppable,
|
||||
origin,
|
||||
acquired_at
|
||||
FROM props.inventory
|
||||
FROM auth.inventory
|
||||
WHERE user_id = $1
|
||||
ORDER BY acquired_at DESC
|
||||
"#,
|
||||
|
|
@ -48,11 +48,11 @@ pub async fn drop_inventory_item<'e>(
|
|||
r#"
|
||||
WITH item_info AS (
|
||||
SELECT id, is_droppable
|
||||
FROM props.inventory
|
||||
FROM auth.inventory
|
||||
WHERE id = $1 AND user_id = $2
|
||||
),
|
||||
deleted AS (
|
||||
DELETE FROM props.inventory
|
||||
DELETE FROM auth.inventory
|
||||
WHERE id = $1 AND user_id = $2 AND is_droppable = true
|
||||
RETURNING id
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub async fn list_channel_loose_props<'e>(
|
|||
r#"
|
||||
SELECT
|
||||
lp.id,
|
||||
lp.channel_id,
|
||||
lp.instance_id as channel_id,
|
||||
lp.server_prop_id,
|
||||
lp.realm_prop_id,
|
||||
ST_X(lp.position) as position_x,
|
||||
|
|
@ -27,10 +27,10 @@ pub async fn list_channel_loose_props<'e>(
|
|||
lp.created_at,
|
||||
COALESCE(sp.name, rp.name) as prop_name,
|
||||
COALESCE(sp.asset_path, rp.asset_path) as prop_asset_path
|
||||
FROM props.loose_props lp
|
||||
FROM scene.loose_props lp
|
||||
LEFT JOIN server.props sp ON lp.server_prop_id = sp.id
|
||||
LEFT JOIN props.realm_props rp ON lp.realm_prop_id = rp.id
|
||||
WHERE lp.channel_id = $1
|
||||
LEFT JOIN realm.props rp ON lp.realm_prop_id = rp.id
|
||||
WHERE lp.instance_id = $1
|
||||
AND (lp.expires_at IS NULL OR lp.expires_at > now())
|
||||
ORDER BY lp.created_at ASC
|
||||
"#,
|
||||
|
|
@ -61,17 +61,17 @@ pub async fn drop_prop_to_canvas<'e>(
|
|||
r#"
|
||||
WITH item_info AS (
|
||||
SELECT id, is_droppable, server_prop_id, realm_prop_id, prop_name, prop_asset_path
|
||||
FROM props.inventory
|
||||
FROM auth.inventory
|
||||
WHERE id = $1 AND user_id = $2
|
||||
),
|
||||
deleted_item AS (
|
||||
DELETE FROM props.inventory
|
||||
DELETE FROM auth.inventory
|
||||
WHERE id = $1 AND user_id = $2 AND is_droppable = true
|
||||
RETURNING id, server_prop_id, realm_prop_id, prop_name, prop_asset_path
|
||||
),
|
||||
inserted_prop AS (
|
||||
INSERT INTO props.loose_props (
|
||||
channel_id,
|
||||
INSERT INTO scene.loose_props (
|
||||
instance_id,
|
||||
server_prop_id,
|
||||
realm_prop_id,
|
||||
position,
|
||||
|
|
@ -88,7 +88,7 @@ pub async fn drop_prop_to_canvas<'e>(
|
|||
FROM deleted_item di
|
||||
RETURNING
|
||||
id,
|
||||
channel_id,
|
||||
instance_id as channel_id,
|
||||
server_prop_id,
|
||||
realm_prop_id,
|
||||
ST_X(position) as position_x,
|
||||
|
|
@ -202,7 +202,7 @@ pub async fn pick_up_loose_prop<'e>(
|
|||
let item = sqlx::query_as::<_, InventoryItem>(
|
||||
r#"
|
||||
WITH deleted_prop AS (
|
||||
DELETE FROM props.loose_props
|
||||
DELETE FROM scene.loose_props
|
||||
WHERE id = $1
|
||||
AND (expires_at IS NULL OR expires_at > now())
|
||||
RETURNING id, server_prop_id, realm_prop_id
|
||||
|
|
@ -219,10 +219,10 @@ pub async fn pick_up_loose_prop<'e>(
|
|||
dp.realm_prop_id
|
||||
FROM deleted_prop dp
|
||||
LEFT JOIN server.props sp ON dp.server_prop_id = sp.id
|
||||
LEFT JOIN props.realm_props rp ON dp.realm_prop_id = rp.id
|
||||
LEFT JOIN realm.props rp ON dp.realm_prop_id = rp.id
|
||||
),
|
||||
inserted_item AS (
|
||||
INSERT INTO props.inventory (
|
||||
INSERT INTO auth.inventory (
|
||||
user_id,
|
||||
server_prop_id,
|
||||
realm_prop_id,
|
||||
|
|
@ -243,7 +243,7 @@ pub async fn pick_up_loose_prop<'e>(
|
|||
si.prop_name,
|
||||
si.prop_asset_path,
|
||||
si.layer,
|
||||
'server_library'::props.prop_origin,
|
||||
'server_library'::server.prop_origin,
|
||||
COALESCE(si.is_transferable, true),
|
||||
COALESCE(si.is_portable, true),
|
||||
COALESCE(si.is_droppable, true),
|
||||
|
|
@ -260,7 +260,7 @@ pub async fn pick_up_loose_prop<'e>(
|
|||
ii.is_transferable,
|
||||
ii.is_portable,
|
||||
ii.is_droppable,
|
||||
'server_library'::props.prop_origin as origin,
|
||||
'server_library'::server.prop_origin as origin,
|
||||
ii.acquired_at
|
||||
FROM inserted_item ii
|
||||
"#,
|
||||
|
|
@ -280,7 +280,7 @@ pub async fn pick_up_loose_prop<'e>(
|
|||
pub async fn cleanup_expired_props<'e>(executor: impl PgExecutor<'e>) -> Result<u64, AppError> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
DELETE FROM props.loose_props
|
||||
DELETE FROM scene.loose_props
|
||||
WHERE expires_at IS NOT NULL AND expires_at <= now()
|
||||
"#,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ pub async fn create_server_prop<'e>(
|
|||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5,
|
||||
$6::props.avatar_layer, $7::props.emotion_state, $8,
|
||||
$6::server.avatar_layer, $7::server.emotion_state, $8,
|
||||
$9
|
||||
)
|
||||
RETURNING
|
||||
|
|
@ -207,7 +207,7 @@ pub async fn upsert_server_prop<'e>(
|
|||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5,
|
||||
$6::props.avatar_layer, $7::props.emotion_state, $8,
|
||||
$6::server.avatar_layer, $7::server.emotion_state, $8,
|
||||
$9
|
||||
)
|
||||
ON CONFLICT (slug) DO UPDATE SET
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ pub async fn get_scene_by_id<'e>(
|
|||
s.updated_at,
|
||||
c.id as default_channel_id
|
||||
FROM realm.scenes s
|
||||
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
|
||||
LEFT JOIN scene.instances c ON c.scene_id = s.id AND c.instance_type = 'public'
|
||||
WHERE s.id = $1
|
||||
"#,
|
||||
)
|
||||
|
|
@ -98,7 +98,7 @@ pub async fn get_scene_by_slug<'e>(
|
|||
s.updated_at,
|
||||
c.id as default_channel_id
|
||||
FROM realm.scenes s
|
||||
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
|
||||
LEFT JOIN scene.instances c ON c.scene_id = s.id AND c.instance_type = 'public'
|
||||
WHERE s.realm_id = $1 AND s.slug = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -316,7 +316,7 @@ pub async fn update_scene<'e>(
|
|||
s.ambient_audio_id, s.ambient_volume, s.sort_order, s.is_entry_point,
|
||||
s.is_hidden, s.created_at, s.updated_at, c.id as default_channel_id
|
||||
FROM realm.scenes s
|
||||
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
|
||||
LEFT JOIN scene.instances c ON c.scene_id = s.id AND c.instance_type = 'public'
|
||||
WHERE s.id = $1"#.to_string()
|
||||
} else {
|
||||
set_clauses.push("updated_at = now()".to_string());
|
||||
|
|
@ -331,7 +331,7 @@ pub async fn update_scene<'e>(
|
|||
)
|
||||
SELECT u.*, c.id as default_channel_id
|
||||
FROM updated u
|
||||
LEFT JOIN realm.channels c ON c.scene_id = u.id AND c.channel_type = 'public'"#,
|
||||
LEFT JOIN scene.instances c ON c.scene_id = u.id AND c.instance_type = 'public'"#,
|
||||
set_clauses.join(", ")
|
||||
)
|
||||
};
|
||||
|
|
@ -442,7 +442,7 @@ pub async fn get_entry_scene_for_realm<'e>(
|
|||
s.updated_at,
|
||||
c.id as default_channel_id
|
||||
FROM realm.scenes s
|
||||
LEFT JOIN realm.channels c ON c.scene_id = s.id AND c.channel_type = 'public'
|
||||
LEFT JOIN scene.instances c ON c.scene_id = s.id AND c.instance_type = 'public'
|
||||
WHERE s.realm_id = $1 AND s.is_hidden = false
|
||||
ORDER BY
|
||||
CASE WHEN s.id = $2 THEN 0 ELSE 1 END,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub async fn list_spots_for_scene<'e>(
|
|||
sort_order,
|
||||
is_visible,
|
||||
is_active
|
||||
FROM realm.spots
|
||||
FROM scene.spots
|
||||
WHERE scene_id = $1
|
||||
ORDER BY sort_order ASC, name ASC NULLS LAST
|
||||
"#,
|
||||
|
|
@ -56,7 +56,7 @@ pub async fn get_spot_by_id<'e>(
|
|||
is_active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM realm.spots
|
||||
FROM scene.spots
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
|
|
@ -90,7 +90,7 @@ pub async fn get_spot_by_slug<'e>(
|
|||
is_active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM realm.spots
|
||||
FROM scene.spots
|
||||
WHERE scene_id = $1 AND slug = $2
|
||||
"#,
|
||||
)
|
||||
|
|
@ -109,7 +109,7 @@ pub async fn is_spot_slug_available<'e>(
|
|||
slug: &str,
|
||||
) -> Result<bool, AppError> {
|
||||
let exists: (bool,) =
|
||||
sqlx::query_as(r#"SELECT EXISTS(SELECT 1 FROM realm.spots WHERE scene_id = $1 AND slug = $2)"#)
|
||||
sqlx::query_as(r#"SELECT EXISTS(SELECT 1 FROM scene.spots WHERE scene_id = $1 AND slug = $2)"#)
|
||||
.bind(scene_id)
|
||||
.bind(slug)
|
||||
.fetch_one(executor)
|
||||
|
|
@ -131,7 +131,7 @@ pub async fn create_spot<'e>(
|
|||
|
||||
let spot = sqlx::query_as::<_, Spot>(
|
||||
r#"
|
||||
INSERT INTO realm.spots (
|
||||
INSERT INTO scene.spots (
|
||||
scene_id, name, slug,
|
||||
region, spot_type,
|
||||
destination_scene_id, destination_position,
|
||||
|
|
@ -139,7 +139,7 @@ pub async fn create_spot<'e>(
|
|||
)
|
||||
VALUES (
|
||||
$1, $2, $3,
|
||||
ST_GeomFromText($4, 0), $5::realm.spot_type,
|
||||
ST_GeomFromText($4, 0), $5::scene.spot_type,
|
||||
$6, CASE WHEN $7 IS NOT NULL THEN ST_GeomFromText($7, 0) ELSE NULL END,
|
||||
$8, $9, $10
|
||||
)
|
||||
|
|
@ -199,7 +199,7 @@ pub async fn update_spot<'e>(
|
|||
param_idx += 1;
|
||||
}
|
||||
if req.spot_type.is_some() {
|
||||
set_clauses.push(format!("spot_type = ${}::realm.spot_type", param_idx));
|
||||
set_clauses.push(format!("spot_type = ${}::scene.spot_type", param_idx));
|
||||
param_idx += 1;
|
||||
}
|
||||
if req.destination_scene_id.is_some() {
|
||||
|
|
@ -236,11 +236,11 @@ pub async fn update_spot<'e>(
|
|||
ST_AsText(destination_position) as destination_position_wkt,
|
||||
current_state, sort_order, is_visible, is_active,
|
||||
created_at, updated_at
|
||||
FROM realm.spots WHERE id = $1"#.to_string()
|
||||
FROM scene.spots WHERE id = $1"#.to_string()
|
||||
} else {
|
||||
set_clauses.push("updated_at = now()".to_string());
|
||||
format!(
|
||||
r#"UPDATE realm.spots SET {}
|
||||
r#"UPDATE scene.spots SET {}
|
||||
WHERE id = $1
|
||||
RETURNING id, scene_id, name, slug, ST_AsText(region) as region_wkt,
|
||||
spot_type, destination_scene_id,
|
||||
|
|
@ -297,7 +297,7 @@ pub async fn delete_spot<'e>(
|
|||
executor: impl PgExecutor<'e>,
|
||||
spot_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
let result = sqlx::query(r#"DELETE FROM realm.spots WHERE id = $1"#)
|
||||
let result = sqlx::query(r#"DELETE FROM scene.spots WHERE id = $1"#)
|
||||
.bind(spot_id)
|
||||
.execute(executor)
|
||||
.await?;
|
||||
|
|
@ -315,7 +315,7 @@ pub async fn get_next_sort_order<'e>(
|
|||
scene_id: Uuid,
|
||||
) -> Result<i32, AppError> {
|
||||
let result: (Option<i32>,) =
|
||||
sqlx::query_as(r#"SELECT MAX(sort_order) FROM realm.spots WHERE scene_id = $1"#)
|
||||
sqlx::query_as(r#"SELECT MAX(sort_order) FROM scene.spots WHERE scene_id = $1"#)
|
||||
.bind(scene_id)
|
||||
.fetch_one(executor)
|
||||
.await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue