Skip to content

feature: auto cancel tournament pause#110

Merged
lukepolo merged 40 commits intomainfrom
feat/auto-cancel-tournament-pause
Mar 5, 2026
Merged

feature: auto cancel tournament pause#110
lukepolo merged 40 commits intomainfrom
feat/auto-cancel-tournament-pause

Conversation

@Flegma
Copy link
Copy Markdown
Contributor

@Flegma Flegma commented Mar 3, 2026

No description provided.

Flegma added 18 commits March 3, 2026 17:45
Resume logic was consolidated into the tournament triggers in 34a0a78.
- can_cancel_match: gate cancel button on privileged roles for Admin mode
- tbu_matches: raise exception for unprivileged cancel in Admin mode
- tournament_brackets: remove nested DECLARE/BEGIN/END, reuse existing var
When teams join a tournament with an existing team, tournament_teams.name
is NULL. The get_team_name function now falls back to the linked
teams.name via tournament_teams.team_id instead of showing the captain's
name.
…nament_finished

- T1 (Adria Cup): add missing parent_bracket_id linking SF1/SF2 to Final
- T2 (Balkan Masters): restructure 6-team bracket with byes for top 2 seeds
  (3 R1 + 2 R2 + Final → 2 R1 + 2 R2 + Final, removing orphaned R1M3)
- check_tournament_finished: skip status update when tournament is
  Paused, Cancelled, or CancelledMinTeams
…ed matches

Add scheduled_at column so organizers can set match times on pending
brackets while a tournament is paused. schedule_tournament_match() now
uses COALESCE(bracket.scheduled_at, now()) and ETA calculation respects
the organizer-set schedule across all stage types.
- Clamp scheduled_at to now() on tournament resume to prevent stale timestamps
- Simplify can_pause/can_resume by removing redundant role checks (is_tournament_organizer covers them)
- Add trailing newline to check_tournament_finished.sql
@Flegma Flegma changed the title WIP: feat/auto cancel tournament pause RDY: feat/auto cancel tournament pause Mar 4, 2026
@Flegma Flegma requested a review from lukepolo March 4, 2026 12:35
@lukepolo lukepolo changed the title RDY: feat/auto cancel tournament pause feature: auto cancel tournament pause Mar 4, 2026
Copy link
Copy Markdown
Contributor

@lukepolo lukepolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I messed up giving the requirements, and am changing them on you a bit.

1. e_match_mode Table

The e_match_mode table defines how a match is started/scheduled.

Schema

  • value (string, primary key)
  • description (string, required)

Allowed Values

value description


admin Match must be scheduled and started by an admin user
auto Match is automatically scheduled by the system

No cancellation logic should exist in this table.


2. match_options Table Changes

Two new columns must be added to match_options.

Migration

ALTER TABLE match_options
ADD COLUMN match_mode VARCHAR NOT NULL REFERENCES e_match_mode(value),
ADD COLUMN track_cancellation BOOLEAN NOT NULL DEFAULT TRUE;

3. Column Definitions

match_mode

Foreign key reference to e_match_mode(value).

Controls who or what starts the match:

  • admin → must be started by an admin
  • auto → automatically started by the system

track_cancellation

Boolean flag controlling whether canceled_at is recorded.

  • TRUE → system sets canceled_at when canceled
  • FALSE → system does NOT set canceled_at

4. Behavior Matrix

match_mode track_cancellation Behavior


admin true Admin start, auto cancellation
admin false Admin start, cancellation ignored
auto true Auto start, auto cancellation
auto false Auto start, cancellation ignored

Comment thread hasura/functions/match/can_cancel_match.sql
Comment thread hasura/functions/tournaments/can_pause_tournament.sql
Comment thread hasura/functions/tournaments/can_resume_tournament.sql
Comment thread hasura/functions/tournaments/check_tournament_finished.sql
Comment thread hasura/triggers/match_maps.sql Outdated
Flegma added 7 commits March 4, 2026 17:43
…el/tournament logic

- Add joined_tournament computed field to guest and user select_permissions
  on tournaments table to fix Hasura 'field not found' errors
- Refine auto-cancel, tournament pause/resume, and round-robin scheduling
- Add migrations for auto_start column and auto_cancel replacement
Extract the duplicated tournament pause/auto_start check from
schedule_next_round_robin_matches and tournament_brackets trigger
into a shared should_auto_schedule() function.
Address PR review: redesign auto_cancel boolean into two fields -
match_mode (admin/auto enum) and track_cancellation (boolean).
Revert check_tournament_finished guard, remove pause-clearing logic
from match_maps trigger, squash migrations into clean schema.
- Add early-return in schedule_tournament_match when match_mode = 'admin'
  to prevent auto-scheduling of admin-only matches
- Add cleanup migration to drop e_auto_cancel_mode table from prior dev runs
… should_auto_schedule

Add explicit auto_start to all tournament INSERTs (T3 uses false for
admin-managed coverage). Set match_mode='admin' on T3 match_options
to exercise the non-default path. Wrap should_auto_schedule return in
COALESCE to guard against NULL tournament lookups.
…duration overrides

Add auto_cancel_duration and live_match_timeout nullable columns to match_options.
Update tbu_matches and tbu_match_maps triggers to use COALESCE override pattern,
replacing hardcoded 3-hour live timeout with configurable live_match_timeout.
@Flegma Flegma requested a review from lukepolo March 5, 2026 13:16
@Flegma Flegma changed the title feature: auto cancel tournament pause RDY feature: auto cancel tournament pause Mar 5, 2026
@lukepolo lukepolo changed the title RDY feature: auto cancel tournament pause feature: auto cancel tournament pause Mar 5, 2026
@@ -0,0 +1,3 @@
ALTER TABLE public.match_options
ADD COLUMN match_mode text NOT NULL DEFAULT 'auto' REFERENCES public.e_match_mode(value),
ADD COLUMN match_cancellation boolean NOT NULL DEFAULT true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets change to auto_cancellation,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be a thing

@Flegma
Copy link
Copy Markdown
Contributor Author

Flegma commented Mar 5, 2026

I messed up giving the requirements, and am changing them on you a bit.

1. e_match_mode Table

The e_match_mode table defines how a match is started/scheduled.

Schema

* `value` (string, primary key)

* `description` (string, required)

Allowed Values

value description

admin Match must be scheduled and started by an admin user auto Match is automatically scheduled by the system

No cancellation logic should exist in this table.

2. match_options Table Changes

Two new columns must be added to match_options.

Migration

ALTER TABLE match_options
ADD COLUMN match_mode VARCHAR NOT NULL REFERENCES e_match_mode(value),
ADD COLUMN track_cancellation BOOLEAN NOT NULL DEFAULT TRUE;

3. Column Definitions

match_mode

Foreign key reference to e_match_mode(value).

Controls who or what starts the match:

* `admin` → must be started by an admin

* `auto` → automatically started by the system

track_cancellation

Boolean flag controlling whether canceled_at is recorded.

* `TRUE` → system sets `canceled_at` when canceled

* `FALSE` → system does NOT set `canceled_at`

4. Behavior Matrix

match_mode track_cancellation Behavior

admin true Admin start, auto cancellation admin false Admin start, cancellation ignored auto true Auto start, auto cancellation auto false Auto start, cancellation ignored

  • e_match_mode table — Done, has admin/auto values, no cancellation logic.
  • match_mode column — Done, FK to e_match_mode(value), default 'auto'.
  • auto_cancellation column (renamed per your later comment from track_cancellation) — boolean, default true.

One thing to check here with you: the spec describes track_cancellation as controlling whether canceled_at is recorded. The current implementation uses it to control whether cancels_at is set - example - it toggles the auto-cancel timer, not just the timestamp. So when auto_cancellation = false, the match won't get an auto-cancel deadline at all. Is that the intended behavior, or should we only suppress the recording of canceled_at?

…me collision

The migration adding auto_cancel_duration column to match_options caused
ambiguous column reference errors in triggers that had a local variable
with the same name.
@lukepolo lukepolo merged commit 363caf6 into main Mar 5, 2026
1 check passed
@lukepolo lukepolo deleted the feat/auto-cancel-tournament-pause branch March 5, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants