database schema adjustments to server/realm/scene

This commit is contained in:
Evan Carroll 2026-01-16 10:57:47 -06:00
parent a102c96bb4
commit 09590edd95
79 changed files with 7100 additions and 100 deletions

View file

@ -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
"#,