Files
OpenFUT-Core/migrations/0020_atomic_sbc_submissions.sql
T
funman300 271c3639ed
CI / Build, lint & test (push) Failing after 52s
feat(sbc): make submissions atomic and durable
2026-08-18 18:26:23 +00:00

15 lines
756 B
SQL

-- 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;