feat(assessment): add table families that pick a variant row by seed

This commit is contained in:
shira committed 2026-10-11 08:19:17 +03:00
1 parent f1147b1885
commit 5e1db37746
16 files changed
+1023 -56

No files matched your search

@@ -0,0 +1,37 @@
-- +goose Up
-- Content hash scheme 2 is the layout of a table generator: a family whose
-- variants are rows of a table, with the answers written in the rows. A new
-- version of such a family is stored with scheme 2. Scheme 1 stays the layout
-- of an algorithmic generator, so existing rows and the hash of every
-- algorithmic version are unchanged, and importing one of them again is still
-- recognized as the same version.
--
-- Only the list of known schemes changes. hash_scheme stays one of the
-- immutable columns that the guard trigger protects.
ALTER TABLE assessment_families
DROP CONSTRAINT assessment_families_hash_scheme_known,
ADD CONSTRAINT assessment_families_hash_scheme_known CHECK (
hash_scheme IN (1, 2)
);
-- +goose Down
-- A stored version never changes and is never removed, so a row of scheme 2
-- cannot be given another scheme. The down step refuses while one exists.
-- +goose StatementBegin
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM assessment_families WHERE hash_scheme = 2) THEN
RAISE EXCEPTION USING
ERRCODE = 'object_not_in_prerequisite_state',
MESSAGE = 'table generator families are stored',
HINT = 'A stored family version cannot be removed or rehashed; keep migration 00047 applied.';
END IF;
END
$$;
-- +goose StatementEnd
ALTER TABLE assessment_families
DROP CONSTRAINT assessment_families_hash_scheme_known,
ADD CONSTRAINT assessment_families_hash_scheme_known CHECK (
hash_scheme IN (1)
);