From 415ad36f998dda20895955ef030c3de9af81b023 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:29:46 +0000 Subject: [PATCH 1/4] Allow Delta Reign (TEF-DLR) Tournaments to be saved The app made TEF-DLR its default Standard format, but the database's commit_tournament_metadata allowlist still stopped at TEF-30C, so creating a Tournament with the default format failed with "Tournament format is not an allowed site format." Add a forward migration that re-creates the function with TEF-DLR in the allowlist, mirror it in schema.sql, point the format rehearsal at the new default, and add a guard that fails when a site format is missing from the database allowlist. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WkSxRaMKK8UtSB1NivqRDs --- schema.sql | 2 +- ...34_allow_delta_reign_tournament_format.sql | 253 ++++++++++++++++++ .../tournament_standard_format_allowlist.sql | 24 +- tests/site-formats.test.ts | 31 ++- 4 files changed, 296 insertions(+), 14 deletions(-) create mode 100644 supabase/migrations/20261109222734_allow_delta_reign_tournament_format.sql diff --git a/schema.sql b/schema.sql index 849e14c3..efae9a55 100644 --- a/schema.sql +++ b/schema.sql @@ -6251,7 +6251,7 @@ begin end if; v_format := p_payload ->> 'format'; if v_format not in ( - 'TEF-30C', 'TEF-PBL', 'TEF-CRI', 'TEF-POR', 'SVI-ASC', 'SVI-PFL', 'SVI-MEG', + 'TEF-DLR', 'TEF-30C', 'TEF-PBL', 'TEF-CRI', 'TEF-POR', 'SVI-ASC', 'SVI-PFL', 'SVI-MEG', 'SVI-WHT/BLK', 'SVI-DRI', 'SVI-JTG', 'BRS-PRE', 'BRS-SSP', 'BRS-SCR', 'Expanded', 'GLC', 'PTCG Pocket' ) then diff --git a/supabase/migrations/20261109222734_allow_delta_reign_tournament_format.sql b/supabase/migrations/20261109222734_allow_delta_reign_tournament_format.sql new file mode 100644 index 00000000..9d918852 --- /dev/null +++ b/supabase/migrations/20261109222734_allow_delta_reign_tournament_format.sql @@ -0,0 +1,253 @@ +-- Add Delta Reign (TEF-DLR) to the Tournament format allowlist. +-- The app made TEF-DLR its default Standard format, so new Tournaments were rejected until this list matched. +-- The prior and updated application versions remain compatible with this function. + +create or replace function public.commit_tournament_metadata( + p_operation text, + p_tournament_id text, + p_request_id text, + p_payload jsonb, + p_expected_tournament_updated_at timestamptz default null +) +returns jsonb +language plpgsql +security definer +set search_path = pg_catalog, public +as $function$ +declare + v_user_id uuid := auth.uid(); + v_command public.tournament_metadata_commands%rowtype; + v_tournament public.tournaments%rowtype; + v_request_id text := nullif(btrim(p_request_id), ''); + v_now timestamptz := clock_timestamp(); + v_payload_hash text; + v_result jsonb; + v_date_from date; + v_date_to date; + v_participation text; + v_format text; + v_placement text; + v_category text; + v_points bigint; +begin + if v_user_id is null then + raise exception using errcode = '42501', message = 'Authentication is required.'; + end if; + if p_operation not in ('create', 'update') then + raise exception using errcode = '22023', message = 'Unsupported Tournament metadata operation.'; + end if; + if v_request_id is null or length(v_request_id) > 200 then + raise exception using errcode = '22023', message = 'A Tournament metadata request id is required.'; + end if; + if p_payload is null or jsonb_typeof(p_payload) is distinct from 'object' then + raise exception using errcode = '22023', message = 'Tournament metadata must be an object.'; + end if; + if nullif(btrim(p_tournament_id), '') is null then + raise exception using errcode = '22023', message = 'Tournament id is required.'; + end if; + if p_operation = 'create' and p_tournament_id <> v_request_id then + raise exception using errcode = '22023', message = 'Tournament id must equal its creation key.'; + end if; + + if nullif(btrim(coalesce(p_payload ->> 'name', '')), '') is null + or p_payload ->> 'name' <> btrim(p_payload ->> 'name') + then + raise exception using errcode = '22023', message = 'Tournament name is required and must be trimmed.'; + end if; + if nullif(btrim(coalesce(p_payload ->> 'format', '')), '') is null + or p_payload ->> 'format' <> btrim(p_payload ->> 'format') + then + raise exception using errcode = '22023', message = 'Tournament format is required and must be trimmed.'; + end if; + v_format := p_payload ->> 'format'; + if v_format not in ( + 'TEF-DLR', 'TEF-30C', 'TEF-PBL', 'TEF-CRI', 'TEF-POR', 'SVI-ASC', 'SVI-PFL', 'SVI-MEG', + 'SVI-WHT/BLK', 'SVI-DRI', 'SVI-JTG', 'BRS-PRE', 'BRS-SSP', 'BRS-SCR', + 'Expanded', 'GLC', 'PTCG Pocket' + ) then + raise exception using errcode = '22023', message = 'Tournament format is not an allowed site format.'; + end if; + begin + v_date_from := nullif(btrim(coalesce(p_payload ->> 'date_from', '')), '')::date; + v_date_to := nullif(btrim(coalesce(p_payload ->> 'date_to', '')), '')::date; + exception when invalid_datetime_format or datetime_field_overflow then + raise exception using errcode = '22023', message = 'Tournament dates must be valid calendar dates.'; + end; + if v_date_from is null or v_date_to is null then + raise exception using errcode = '22023', message = 'Tournament dates are required.'; + end if; + if v_date_to < v_date_from then + raise exception using errcode = '22023', message = 'Tournament end date cannot be before its start date.'; + end if; + + v_participation := coalesce(p_payload ->> 'participation', 'player'); + v_placement := coalesce(p_payload ->> 'placement', ''); + if v_placement not in ( + '', 'no placement', 'dropped', 'second', 'third', 'fourth', 'fifth', + 'sixth', 'seventh', 'eighth', 't1024', 't512', 't256', 't128', 't64', + 't32', 't16', 't8', 't4', 'finalist', 'champion' + ) then + raise exception using errcode = '22023', message = 'Tournament placement is invalid.'; + end if; + if v_participation not in ('player', 'judge') then + raise exception using errcode = '22023', message = 'Tournament participation must be player or judge.'; + end if; + if v_participation = 'judge' then + if p_payload ->> 'judge_role' not in ('judge', 'head judge') then + raise exception using errcode = '22023', message = 'A valid judge role is required for judge participation.'; + end if; + if nullif(p_payload ->> 'placement', '') is not null then + raise exception using errcode = '22023', message = 'Judges cannot have a player placement.'; + end if; + elsif nullif(p_payload ->> 'judge_role', '') is not null then + raise exception using errcode = '22023', message = 'Player tournaments cannot have a judge role.'; + end if; + if v_participation = 'player' and p_payload ->> 'professor_points' is not null then + raise exception using errcode = '22023', message = 'Professor Points are only valid for judge participation.'; + end if; + if v_participation = 'judge' and p_payload ->> 'championship_points' is not null then + raise exception using errcode = '22023', message = 'Championship Points are only valid for player participation.'; + end if; + if v_participation = 'player' and p_payload ->> 'championship_points' is not null then + if p_payload ->> 'championship_points' !~ '^[0-9]+$' then + raise exception using errcode = '22023', message = 'Championship Points must be a whole number of 0 or more.'; + end if; + begin + v_points := (p_payload ->> 'championship_points')::bigint; + exception when invalid_text_representation or numeric_value_out_of_range then + raise exception using errcode = '22023', message = 'Championship Points must be a whole number of 0 or more.'; + end; + if v_points > 2147483647 then + raise exception using errcode = '22023', message = 'Championship Points are too large to save.'; + end if; + end if; + if v_participation = 'judge' and p_payload ->> 'professor_points' is not null then + if p_payload ->> 'professor_points' !~ '^[0-9]+$' then + raise exception using errcode = '22023', message = 'Professor Points must be a whole number of 0 or more.'; + end if; + begin + v_points := (p_payload ->> 'professor_points')::bigint; + exception when invalid_text_representation or numeric_value_out_of_range then + raise exception using errcode = '22023', message = 'Professor Points must be a whole number of 0 or more.'; + end; + if v_points > 2147483647 then + raise exception using errcode = '22023', message = 'Professor Points are too large to save.'; + end if; + end if; + v_category := coalesce(p_payload ->> 'category', ''); + if v_category not in ('', 'online', 'local', 'challenge', 'cup', 'prerelease', 'regional', 'international', 'world') then + raise exception using errcode = '22023', message = 'Tournament category is invalid.'; + end if; + + perform pg_advisory_xact_lock( + hashtextextended(v_user_id::text || ':tournament-metadata:' || v_request_id, 0) + ); + v_payload_hash := md5(jsonb_build_object( + 'operation', p_operation, + 'tournamentId', p_tournament_id, + 'payload', p_payload + )::text); + + select * into v_command + from public.tournament_metadata_commands + where user_id = v_user_id and request_id = v_request_id + for update; + if found then + if v_command.payload_hash <> v_payload_hash then + raise exception using errcode = '23505', message = 'That Tournament metadata request id was already used with different values.'; + end if; + return jsonb_set(v_command.result, '{status}', '"idempotent"'::jsonb); + end if; + + if nullif(p_payload ->> 'linked_deck_id', '') is not null + and not exists ( + select 1 from public.decks + where id = nullif(p_payload ->> 'linked_deck_id', '') + and user_id = v_user_id + ) + then + raise exception using errcode = '42501', message = 'The linked Deck Strategy is not owned by this account.'; + end if; + if nullif(p_payload ->> 'linked_deck_list_id', '') is not null + and not public.can_use_deck_list_reference( + v_user_id, + nullif(p_payload ->> 'linked_deck_id', ''), + nullif(p_payload ->> 'linked_deck_list_id', '') + ) + then + raise exception using errcode = '42501', message = 'The linked Deck List is not owned by this account.'; + end if; + + if p_operation = 'create' then + if exists (select 1 from public.tournaments where id = p_tournament_id) then + raise exception using errcode = '23505', message = 'That Tournament creation identity is already in use.'; + end if; + insert into public.tournaments ( + id, user_id, name, tournament_identifier, location, + championship_points, professor_points, date_from, date_to, + linked_deck_id, linked_deck_list_id, deck_name, deck_sprites, + category, placement, participation, judge_role, format, notes, + created_at, updated_at + ) values ( + p_tournament_id, v_user_id, + coalesce(p_payload ->> 'name', ''), coalesce(p_payload ->> 'tournament_identifier', ''), + coalesce(p_payload ->> 'location', ''), + case when p_payload ? 'championship_points' and p_payload ->> 'championship_points' is not null then (p_payload ->> 'championship_points')::integer else null end, + case when p_payload ? 'professor_points' and p_payload ->> 'professor_points' is not null then (p_payload ->> 'professor_points')::integer else null end, + (p_payload ->> 'date_from')::date, (p_payload ->> 'date_to')::date, + nullif(p_payload ->> 'linked_deck_id', ''), nullif(p_payload ->> 'linked_deck_list_id', ''), + coalesce(p_payload ->> 'deck_name', ''), coalesce(p_payload -> 'deck_sprites', '[]'::jsonb), + coalesce(p_payload ->> 'category', ''), coalesce(p_payload ->> 'placement', ''), + coalesce(p_payload ->> 'participation', 'player'), nullif(p_payload ->> 'judge_role', ''), + coalesce(p_payload ->> 'format', ''), coalesce(p_payload ->> 'notes', ''), v_now, v_now + ) returning * into v_tournament; + else + select * into v_tournament + from public.tournaments + where id = p_tournament_id and user_id = v_user_id + for update; + if not found then + raise exception using errcode = 'P0002', message = 'Tournament could not be found.'; + end if; + if p_expected_tournament_updated_at is null + or v_tournament.updated_at is distinct from p_expected_tournament_updated_at + then + raise exception using errcode = 'P0001', message = 'Tournament changed; refresh-and-retry before saving.'; + end if; + update public.tournaments + set name = coalesce(p_payload ->> 'name', ''), + tournament_identifier = coalesce(p_payload ->> 'tournament_identifier', ''), + location = coalesce(p_payload ->> 'location', ''), + championship_points = case when p_payload ? 'championship_points' and p_payload ->> 'championship_points' is not null then (p_payload ->> 'championship_points')::integer else null end, + professor_points = case when p_payload ? 'professor_points' and p_payload ->> 'professor_points' is not null then (p_payload ->> 'professor_points')::integer else null end, + date_from = (p_payload ->> 'date_from')::date, + date_to = (p_payload ->> 'date_to')::date, + linked_deck_id = nullif(p_payload ->> 'linked_deck_id', ''), + linked_deck_list_id = nullif(p_payload ->> 'linked_deck_list_id', ''), + deck_name = coalesce(p_payload ->> 'deck_name', ''), + deck_sprites = coalesce(p_payload -> 'deck_sprites', '[]'::jsonb), + category = coalesce(p_payload ->> 'category', ''), + placement = coalesce(p_payload ->> 'placement', ''), + participation = coalesce(p_payload ->> 'participation', 'player'), + judge_role = nullif(p_payload ->> 'judge_role', ''), + format = coalesce(p_payload ->> 'format', ''), + notes = coalesce(p_payload ->> 'notes', ''), + updated_at = v_now + where id = p_tournament_id and user_id = v_user_id + returning * into v_tournament; + end if; + + v_result := jsonb_build_object( + 'status', 'committed', 'tournamentId', v_tournament.id, + 'requestId', v_request_id, 'updatedAt', v_tournament.updated_at + ); + insert into public.tournament_metadata_commands ( + id, user_id, tournament_id, operation, request_id, payload_hash, result + ) values ( + gen_random_uuid()::text, v_user_id, v_tournament.id, p_operation, v_request_id, v_payload_hash, v_result + ); + return v_result; +end; +$function$; +revoke all on function public.commit_tournament_metadata(text, text, text, jsonb, timestamptz) from public, anon; +grant execute on function public.commit_tournament_metadata(text, text, text, jsonb, timestamptz) to authenticated; diff --git a/supabase/rehearsals/tournament_standard_format_allowlist.sql b/supabase/rehearsals/tournament_standard_format_allowlist.sql index 6daa8e34..27a5ac45 100644 --- a/supabase/rehearsals/tournament_standard_format_allowlist.sql +++ b/supabase/rehearsals/tournament_standard_format_allowlist.sql @@ -1,4 +1,4 @@ --- Run against a disposable database after the 30C allowlist migration. +-- Run against a disposable database after the latest Tournament format allowlist migration. -- Verify the new default, the previous format, and the rejection boundary. insert into auth.users ( instance_id, id, aud, role, email, encrypted_password, @@ -21,32 +21,32 @@ declare v_invalid_rejected boolean := false; begin v_result := public.commit_tournament_metadata( - 'create', 'format-rehearsal-30c', 'format-rehearsal-30c', + 'create', 'format-rehearsal-dlr', 'format-rehearsal-dlr', jsonb_build_object( - 'name', '30th Celebration', 'date_from', current_date::text, - 'date_to', current_date::text, 'format', 'TEF-30C' + 'name', 'Delta Reign', 'date_from', current_date::text, + 'date_to', current_date::text, 'format', 'TEF-DLR' ) ); if v_result ->> 'status' <> 'committed' - or (select format from public.tournaments where id = 'format-rehearsal-30c') <> 'TEF-30C' + or (select format from public.tournaments where id = 'format-rehearsal-dlr') <> 'TEF-DLR' then - raise exception 'TEF-30C Tournament create did not commit'; + raise exception 'TEF-DLR Tournament create did not commit'; end if; select updated_at into strict v_updated_at - from public.tournaments where id = 'format-rehearsal-30c'; + from public.tournaments where id = 'format-rehearsal-dlr'; v_result := public.commit_tournament_metadata( - 'update', 'format-rehearsal-30c', 'format-rehearsal-pbl-update', + 'update', 'format-rehearsal-dlr', 'format-rehearsal-30c-update', jsonb_build_object( - 'name', 'Pitch Black', 'date_from', current_date::text, - 'date_to', current_date::text, 'format', 'TEF-PBL' + 'name', '30th Celebration', 'date_from', current_date::text, + 'date_to', current_date::text, 'format', 'TEF-30C' ), v_updated_at ); if v_result ->> 'status' <> 'committed' - or (select format from public.tournaments where id = 'format-rehearsal-30c') <> 'TEF-PBL' + or (select format from public.tournaments where id = 'format-rehearsal-dlr') <> 'TEF-30C' then - raise exception 'existing TEF-PBL Tournament update regressed'; + raise exception 'existing TEF-30C Tournament update regressed'; end if; begin diff --git a/tests/site-formats.test.ts b/tests/site-formats.test.ts index 7a2ccc95..23605928 100644 --- a/tests/site-formats.test.ts +++ b/tests/site-formats.test.ts @@ -1,10 +1,12 @@ import assert from "node:assert/strict"; +import { readdirSync, readFileSync } from "node:fs"; import test from "node:test"; import { extractSiteFormatCodes, getDefaultSiteFormat, - isKnownSiteFormat + isKnownSiteFormat, + SITE_FORMAT_OPTIONS } from "../lib/formats/options"; test("site format fallback defaults to the newest Standard range and recognizes current special cases", () => { @@ -23,3 +25,30 @@ test("site format fallback defaults to the newest Standard range and recognizes ["TEF-30C", "SVI-WHT/BLK"] ); }); + +function readTournamentFormatAllowlist(sql: string) { + const definitions = sql + .split("create or replace function public.commit_tournament_metadata(") + .slice(1); + const list = definitions.at(-1)?.match(/v_format not in \(([^)]*)\)/)?.[1]; + assert(list, "commit_tournament_metadata must declare a Tournament format allowlist"); + return [...list.matchAll(/'([^']+)'/g)].map((match) => match[1]).sort(); +} + +test("every site format can be saved on a Tournament by the database", () => { + const migrationsDir = new URL("../supabase/migrations/", import.meta.url); + const latestMigration = readdirSync(migrationsDir) + .filter((name) => name.endsWith(".sql")) + .sort() + .map((name) => readFileSync(new URL(name, migrationsDir), "utf8")) + .filter((sql) => sql.includes("create or replace function public.commit_tournament_metadata(")) + .at(-1); + assert(latestMigration, "a migration must define commit_tournament_metadata"); + const siteFormats = [...SITE_FORMAT_OPTIONS].sort(); + + assert.deepEqual(readTournamentFormatAllowlist(latestMigration), siteFormats); + assert.deepEqual( + readTournamentFormatAllowlist(readFileSync(new URL("../schema.sql", import.meta.url), "utf8")), + siteFormats + ); +}); From 19bd4f0c9bfc39e0b318fd4bbf17c72d956b3726 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:34:30 +0000 Subject: [PATCH 2/4] Fold the format allowlist guard into the existing site-format case Keeps the executed-case count unchanged, per the zero-growth test policy for non-feature changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WkSxRaMKK8UtSB1NivqRDs --- tests/site-formats.test.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/site-formats.test.ts b/tests/site-formats.test.ts index 23605928..d0939aae 100644 --- a/tests/site-formats.test.ts +++ b/tests/site-formats.test.ts @@ -9,7 +9,16 @@ import { SITE_FORMAT_OPTIONS } from "../lib/formats/options"; -test("site format fallback defaults to the newest Standard range and recognizes current special cases", () => { +function readTournamentFormatAllowlist(sql: string) { + const definitions = sql + .split("create or replace function public.commit_tournament_metadata(") + .slice(1); + const list = definitions.at(-1)?.match(/v_format not in \(([^)]*)\)/)?.[1]; + assert(list, "commit_tournament_metadata must declare a Tournament format allowlist"); + return [...list.matchAll(/'([^']+)'/g)].map((match) => match[1]).sort(); +} + +test("site formats default to the newest Standard range, recognize special cases, and are all savable on a Tournament", () => { assert.equal(getDefaultSiteFormat(), "TEF-DLR"); assert.equal(getDefaultSiteFormat(["TEF-30C"]), "TEF-DLR"); assert.equal(getDefaultSiteFormat(["TEF-PBL"]), "TEF-DLR"); @@ -24,18 +33,8 @@ test("site format fallback defaults to the newest Standard range and recognizes ), ["TEF-30C", "SVI-WHT/BLK"] ); -}); -function readTournamentFormatAllowlist(sql: string) { - const definitions = sql - .split("create or replace function public.commit_tournament_metadata(") - .slice(1); - const list = definitions.at(-1)?.match(/v_format not in \(([^)]*)\)/)?.[1]; - assert(list, "commit_tournament_metadata must declare a Tournament format allowlist"); - return [...list.matchAll(/'([^']+)'/g)].map((match) => match[1]).sort(); -} - -test("every site format can be saved on a Tournament by the database", () => { + // The database rejects any Tournament format missing from its allowlist, so every site format must be on it. const migrationsDir = new URL("../supabase/migrations/", import.meta.url); const latestMigration = readdirSync(migrationsDir) .filter((name) => name.endsWith(".sql")) @@ -45,7 +44,6 @@ test("every site format can be saved on a Tournament by the database", () => { .at(-1); assert(latestMigration, "a migration must define commit_tournament_metadata"); const siteFormats = [...SITE_FORMAT_OPTIONS].sort(); - assert.deepEqual(readTournamentFormatAllowlist(latestMigration), siteFormats); assert.deepEqual( readTournamentFormatAllowlist(readFileSync(new URL("../schema.sql", import.meta.url), "utf8")), From 06b626631519c7918ccfa746aaf6f5f747737d04 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 23:23:36 +0000 Subject: [PATCH 3/4] Deploy database migrations from the merging session James does not review or approve deployments, so a merged migration should reach production without handing the deploy back to him. The session that merges a migration PR now dispatches the Deploy production database workflow on main and reports the result. Agents still never apply SQL to production any other way. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WkSxRaMKK8UtSB1NivqRDs --- .claude/skills/steward/SKILL.md | 10 ++++++++++ AGENTS.md | 2 +- README.md | 2 +- docs/migration-release.md | 10 +++++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.claude/skills/steward/SKILL.md b/.claude/skills/steward/SKILL.md index 62707db0..2286cfcf 100644 --- a/.claude/skills/steward/SKILL.md +++ b/.claude/skills/steward/SKILL.md @@ -46,6 +46,16 @@ If you are awake when the PR goes green, merge it yourself rather than waiting f Merge with **squash**, keeping the PR title and number as the commit subject, and pin the merge to the head SHA you just checked (`expectedHeadSha`, or `gh pr merge --match-head-commit`) so a later push cannot slip in. Treat the merge call's result as a diagnostic: confirm with a separate read that the PR is merged at that SHA before telling James, in one line, and never retry a merge on the call's result alone. See `docs/verification-commands.md` **Pull request integration is a two-phase contract**. +## Deploy database migrations + +If the merged PR added or changed files under `supabase/migrations/`, the change is not live until the production database workflow runs. Run it yourself right after confirming the merge, without asking James. The PR request already covers it (`docs/migration-release.md` **4. Deploy through GitHub Actions**). + +- Confirm `origin/main` is the merge commit or a descendant of it, then dispatch `deploy-production-database.yml` on `main` with `confirmation=DEPLOY`. +- The run's completion does not wake you. Check it a few minutes later; it usually takes about two minutes. +- On success, confirm the new migration version is applied (the run's **Verify migration history** step, or a read-only migration list), and tell James in one line together with the merge. +- On failure, do not re-run. Read the failing step's log and tell James what failed. +- Never apply migration SQL to production any other way. + ## Update local main After confirming the merge (yours, or the workflow's when you next wake), bring James's local `main` up to date with `origin/main`. Fast-forward only, and never discard local work: diff --git a/AGENTS.md b/AGENTS.md index f77a98b9..edc1d3ff 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,7 +27,7 @@ This block is written and re-added by `next dev` — verify at `node_modules/nex - **Domain language:** Before naming or changing a product concept, read `CONTEXT.md`. Deck Aggregate compatibility work also requires `docs/adr/0001-preserve-deck-aggregate-during-relational-cutover.md`; Deck List ownership, Deck Strategy association, or Tournament snapshot work also requires `docs/adr/0002-first-class-deck-lists-and-tournament-snapshots.md`. - **Notion issues:** Before reading, creating, triaging, or updating an issue or specification, read `docs/agents/issue-tracker.md`. -- **Database migrations:** Before authoring, reviewing, or releasing a Supabase schema change, read `docs/migration-release.md`. Local hooks validate; only the controlled production workflow deploys. +- **Database migrations:** Before authoring, reviewing, or releasing a Supabase schema change, read `docs/migration-release.md`. Local hooks validate; only the controlled production workflow deploys, and the session that merges a migration dispatches it. - **Reference data:** Before changing a catalog or cached reference dataset, read `docs/agents/reference-data.md`. - **Battle Replay:** Before changing Battle Replay reconstruction, display, card information or its tests, read `docs/agents/battle-replay-rules.md`. It is James's authoritative game-rule contract and overrides any earlier "never infer" guidance, including the prototype's productisation note. Measure success against real saved logs, never invented log wording. - **Deck-list ordering:** Before changing a deck-list sort, snapshot, share, or `sortedCards` path, read `docs/agents/deck-list-ordering.md`. diff --git a/README.md b/README.md index 76ad1462..bb59a93e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ cp .env.example .env - For a new Supabase project, apply [`schema.sql`](./schema.sql). It is the complete schema snapshot; do not replay the historical incremental SQL over it. - For an existing environment, inspect migration history and the target schema before applying anything. [`supabase/migrations`](./supabase/migrations) is the release authority. [`sql`](./sql) is historical reference material, not a fresh-install sequence or a destination for new migrations. -- Local Git hooks validate database changes without deploying them. Production migrations run only through the manually dispatched `Deploy production database` workflow after merge to `main`; see [`docs/migration-release.md`](./docs/migration-release.md). +- Local Git hooks validate database changes without deploying them. Production migrations run only through the `Deploy production database` workflow, which the merging session dispatches after merge to `main`; see [`docs/migration-release.md`](./docs/migration-release.md). 5. Configure Supabase Auth redirect URLs for each environment: diff --git a/docs/migration-release.md b/docs/migration-release.md index 40b640d9..ac108762 100644 --- a/docs/migration-release.md +++ b/docs/migration-release.md @@ -2,7 +2,7 @@ Use this path for every Supabase schema change. `supabase/migrations/` and Supabase's migration history are the release authority. `schema.sql` is the fresh-project snapshot; `sql/` is historical reference material. -Local agents and Git hooks validate migrations. They have no production-deployment step. Production changes run only from the reviewed `main` commit through the manually dispatched **Deploy production database** GitHub workflow. +Local agents and Git hooks validate migrations. They never apply SQL to production themselves. Production changes run only from the reviewed `main` commit through the **Deploy production database** GitHub workflow, which the session that merged the migration dispatches. ## 1. Author a native migration @@ -72,11 +72,11 @@ the application cutover; it must not be included in this release. ## 4. Deploy through GitHub Actions -Configure the GitHub `Production` environment with the `SUPABASE_PRODUCTION_DB_URL` secret. Restrict that environment to `main` and add a required reviewer when the repository plan supports it. +Configure the GitHub `Production` environment with the `SUPABASE_PRODUCTION_DB_URL` secret and restrict it to `main`. -From the merged `main` commit, manually run **Deploy production database** and enter `DEPLOY`. The workflow serializes production database runs, previews pending migrations with `supabase db push --dry-run`, applies them with `supabase db push`, then verifies migration history, repository schema contracts, and Supabase security advisors. +**Standing decision — 9 November 2026:** James does not review or approve deployments. A migration is reviewed in its pull request (CI, `Database behavior` and review threads), and merging it authorizes deploying it. After a pull request that adds or changes files under `supabase/migrations/` merges, the session that drove it dispatches **Deploy production database** on `main` with the confirmation `DEPLOY` (`gh workflow run deploy-production-database.yml --ref main -f confirmation=DEPLOY`, or the GitHub Actions `run_workflow` tool), once `origin/main` is the merge commit or a descendant of it. Do not hand this step back to James. The workflow serializes production database runs, previews pending migrations with `supabase db push --dry-run`, applies them with `supabase db push`, then verifies migration history, repository schema contracts, and Supabase security advisors. -The workflow is the only production migration path. A local `git push`, agent command, Vercel build, or preview deployment never applies production SQL. +The workflow is the only production migration path. A local `git push`, direct SQL from an agent (Supabase connector, `psql`, or `supabase db push` against production), Vercel build, or preview deployment never applies production SQL. If the workflow reports history drift, stop. Inspect `supabase migration list` and the target schema before considering `migration repair`; repairing history requires a separate reviewed decision because it changes the ledger without applying SQL. @@ -90,7 +90,7 @@ Database work is complete when all applicable evidence is green: 4. the compatible production application path behaves as intended; 5. monitoring and the rollback or forward-fix owner are recorded. -If production deployment was not requested or could not run, report it as outstanding and keep the database work incomplete. +If the deployment could not run or failed, report it as outstanding and keep the database work incomplete. ## Import Draft retention release From d7e12d09fc72e15749c9850fa9624b4775565ca2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 23:27:38 +0000 Subject: [PATCH 4/4] Stack Tournament deck actions under the deck name on phones On narrow screens the deck row kept the name and its action buttons on one line, so the name wrapped word by word and the buttons ran off the screen. Below the sm breakpoint the actions now wrap onto their own full-width row; the desktop layout is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WkSxRaMKK8UtSB1NivqRDs --- app/(app)/tournaments/[id]/page.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/(app)/tournaments/[id]/page.tsx b/app/(app)/tournaments/[id]/page.tsx index 0fd2984e..4ae22a13 100644 --- a/app/(app)/tournaments/[id]/page.tsx +++ b/app/(app)/tournaments/[id]/page.tsx @@ -257,23 +257,23 @@ export default async function TournamentDetailPage({ params }: TournamentDetailP
-
+
{isJudge ? ( ) : ( )} -
-
+
+
{isJudge ? getTournamentJudgeRoleLabel(tournament.judgeRole) : stackDeckName(tournamentDeckName)}
-
+
{isJudge ? null : resolvedTournamentDeckList ? ( -
+
) : ( -
+