Skip to content

Commit

Permalink
fix: ランキングビューの定義をミスってたので修正
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-shobon committed Nov 9, 2024
1 parent 5e29e5d commit 8f462c8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions supabase/migrations/20241109220031_fix_filter_guest_on_stats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- ゲストを除外したプロフィールのステータスを取得するビューを作成する
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,
CASE WHEN max(players.score) IS NULL
THEN NULL
ELSE rank() OVER (ORDER BY max(players.score) DESC NULLS LAST)
END 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;

0 comments on commit 8f462c8

Please sign in to comment.