summaryrefslogtreecommitdiff
path: root/schema.sql
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-11-24 14:41:49 +0100
committerTor Andersson <tor@ccxvii.net>2023-01-31 12:39:03 +0100
commit8e20d731f055f5a0f6ce7c63157eb0c8b8ac6778 (patch)
tree72a154f3c3e42bea51e14be28cad8ac325cb2a24 /schema.sql
parente94eac9df7688b8742eac0ccd13bad897013bfbc (diff)
downloadserver-8e20d731f055f5a0f6ce7c63157eb0c8b8ac6778.tar.gz
Move user dynamic info into SQL view.
Diffstat (limited to 'schema.sql')
-rw-r--r--schema.sql33
1 files changed, 33 insertions, 0 deletions
diff --git a/schema.sql b/schema.sql
index 0ff0cc2..d4a6864 100644
--- a/schema.sql
+++ b/schema.sql
@@ -79,6 +79,39 @@ create view user_profile_view as
natural left join user_last_seen
;
+drop view if exists user_dynamic_view;
+create view user_dynamic_view as
+ select
+ user_id,
+ name,
+ mail,
+ (
+ select
+ count(*)
+ from
+ messages
+ where
+ to_id = user_id
+ and is_read = 0
+ and is_deleted_from_inbox = 0
+ ) as unread,
+ (
+ select
+ count(*)
+ from
+ players
+ join games using(game_id)
+ join game_state using(game_id)
+ where
+ status = 1
+ and players.user_id = users.user_id
+ and active in ( players.role, 'Both', 'All' )
+ ) as active,
+ is_banned
+ from
+ users
+ ;
+
-- Friend and Block Lists --
create table if not exists contacts (