Files
lincodex/backend/db/migrations/00047_allow_table_hash_scheme.sql
T

38 lines
1.5 KiB
SQL

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