-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5cef59
commit 5e29e5d
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
supabase/migrations/20241109183830_filter_guest_on_stats.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- ゲストを除外したプロフィールのステータスを取得するビューを作成する | ||
DROP VIEW public.profiles_with_stats; | ||
|
||
CREATE VIEW public.profiles_with_stats | ||
WITH (security_invoker = TRUE) | ||
AS | ||
SELECT | ||
profiles.*, | ||
CASE | ||
WHEN profiles.is_guest = TRUE THEN NULL | ||
ELSE player_stats.high_score | ||
END AS high_score, | ||
CASE | ||
WHEN profiles.is_guest = TRUE THEN 0 | ||
ELSE player_stats.play_count | ||
END AS play_count, | ||
CASE | ||
WHEN profiles.is_guest = TRUE THEN NULL | ||
ELSE player_stats.rank | ||
END AS rank | ||
FROM | ||
public.profiles | ||
LEFT JOIN ( | ||
SELECT | ||
profiles.id AS profile_id, | ||
max(players.score) AS high_score, | ||
count(players.id) AS play_count, | ||
rank() OVER (ORDER BY max(players.score) DESC NULLS LAST) AS rank | ||
FROM | ||
public.profiles | ||
LEFT JOIN | ||
public.players ON profiles.user_id = players.user_id | ||
WHERE | ||
profiles.is_guest = FALSE | ||
GROUP BY | ||
profiles.id | ||
) AS player_stats ON profiles.id = player_stats.profile_id; |