File tree Expand file tree Collapse file tree
hasura/functions/tournaments Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ CREATE OR REPLACE FUNCTION public .resume_tournament(_tournament_id uuid)
2+ RETURNS void
3+ LANGUAGE plpgsql
4+ AS $$
5+ DECLARE
6+ bracket_row tournament_brackets%ROWTYPE;
7+ _tournament_status text ;
8+ BEGIN
9+ SELECT status INTO _tournament_status FROM tournaments WHERE id = _tournament_id;
10+
11+ IF _tournament_status != ' Paused' THEN
12+ RAISE EXCEPTION ' Tournament is not paused' USING ERRCODE = ' 22000' ;
13+ END IF;
14+
15+ -- Set status back to Live
16+ UPDATE tournaments SET status = ' Live' WHERE id = _tournament_id;
17+
18+ -- Schedule all ready brackets that were blocked during pause
19+ FOR bracket_row IN
20+ SELECT tb.*
21+ FROM tournament_brackets tb
22+ INNER JOIN tournament_stages ts ON ts .id = tb .tournament_stage_id
23+ WHERE ts .tournament_id = _tournament_id
24+ AND tb .match_id IS NULL
25+ AND tb .finished = false
26+ AND tb .tournament_team_id_1 IS NOT NULL
27+ AND tb .tournament_team_id_2 IS NOT NULL
28+ ORDER BY tb .round , tb .match_number
29+ LOOP
30+ PERFORM schedule_tournament_match(bracket_row);
31+ END LOOP;
32+
33+ -- Recalculate ETAs
34+ PERFORM calculate_tournament_bracket_start_times(_tournament_id);
35+ END;
36+ $$;
You can’t perform that action at this time.
0 commit comments