feat(sbc): make submissions atomic and durable
CI / Build, lint & test (push) Failing after 52s

This commit is contained in:
funman300
2026-08-18 18:26:23 +00:00
parent 637a21eac1
commit 271c3639ed
7 changed files with 1264 additions and 85 deletions
@@ -0,0 +1,14 @@
-- Durable replay and non-repeatable-completion guards for atomic SBC submissions.
-- Existing successful rows are treated as non-repeatable; if historical data already
-- violates that invariant the migration fails rather than silently discarding history.
ALTER TABLE sbc_submissions ADD COLUMN repeatable INTEGER NOT NULL DEFAULT 0;
CREATE UNIQUE INDEX idx_sbc_nonrepeatable_completion
ON sbc_submissions(profile_id, sbc_id)
WHERE passed = 1 AND repeatable = 0;
-- submitted_card_ids is stored in canonical sorted order by the writer. This rejects
-- stale retries of the same card set even for explicitly repeatable challenges.
CREATE UNIQUE INDEX idx_sbc_submission_replay
ON sbc_submissions(profile_id, sbc_id, submitted_card_ids)
WHERE passed = 1;