File tree Expand file tree Collapse file tree
hasura/migrations/default/1776430500000_tournament_trophies_unique_include_placement Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11ALTER TABLE public .tournament_trophies
2- DROP CONSTRAINT tournament_trophies_tournament_team_player_placement_key;
2+ DROP CONSTRAINT IF EXISTS tournament_trophies_tournament_team_player_placement_key;
33
44ALTER TABLE public .tournament_trophies
55 ADD CONSTRAINT tournament_trophies_tournament_id_tournament_team_id_player_key
Original file line number Diff line number Diff line change 11-- Allow a player to hold both a placement trophy (gold/silver/bronze) and MVP
22-- on the same tournament. The old uniqueness key blocked the second insert
33-- when the MVP was on the winning team.
4- ALTER TABLE public .tournament_trophies
5- DROP CONSTRAINT tournament_trophies_tournament_id_tournament_team_id_player_key;
4+ --
5+ -- The previous constraint was created via an inline UNIQUE (...) in the
6+ -- original migration, so its name is auto-generated by Postgres. The exact
7+ -- truncation of that name varies across Postgres versions / NAMEDATALEN, so
8+ -- look it up by column set instead of relying on the expected name.
9+ DO $$
10+ DECLARE
11+ v_conname text ;
12+ BEGIN
13+ SELECT c .conname
14+ INTO v_conname
15+ FROM pg_constraint c
16+ WHERE c .conrelid = ' public.tournament_trophies' ::regclass
17+ AND c .contype = ' u'
18+ AND (
19+ SELECT array_agg(a .attname ORDER BY a .attname )
20+ FROM unnest(c .conkey ) AS k(attnum)
21+ JOIN pg_attribute a
22+ ON a .attrelid = c .conrelid AND a .attnum = k .attnum
23+ ) = ARRAY[' player_steam_id' , ' tournament_id' , ' tournament_team_id' ]::text [];
24+
25+ IF v_conname IS NOT NULL THEN
26+ EXECUTE ' ALTER TABLE public.tournament_trophies DROP CONSTRAINT ' || quote_ident(v_conname);
27+ END IF;
28+ END $$;
629
730ALTER TABLE public .tournament_trophies
831 ADD CONSTRAINT tournament_trophies_tournament_team_player_placement_key
You can’t perform that action at this time.
0 commit comments