-- Admit the 'merge' reason into retained_identities. An account merge folds a secondary -- account into a primary; when both hold an identity of the same kind (e.g. each has a -- confirmed email), the survivor keeps its own and the secondary's is journaled to the -- legal dossier and removed — so the survivor never ends up with two identities of one -- kind, and the absorbed credential is still retained. That journal row carries reason -- 'merge', alongside the existing unlink / change / delete. -- -- Expand-contract: the Up only WIDENS the allowed reason set, so an older backend image -- (which writes only unlink/change/delete) still satisfies the constraint — a rollback -- stays DB-safe. The Down narrows it again and would reject pre-existing 'merge' rows, so -- it is a dev-only convenience, not a production rollback path (image rollback runs old -- code against this schema, not the Down migration). -- +goose Up ALTER TABLE backend.retained_identities DROP CONSTRAINT retained_identities_reason_chk; ALTER TABLE backend.retained_identities ADD CONSTRAINT retained_identities_reason_chk CHECK ((reason = ANY (ARRAY['unlink'::text, 'change'::text, 'delete'::text, 'merge'::text]))); -- +goose Down ALTER TABLE backend.retained_identities DROP CONSTRAINT retained_identities_reason_chk; ALTER TABLE backend.retained_identities ADD CONSTRAINT retained_identities_reason_chk CHECK ((reason = ANY (ARRAY['unlink'::text, 'change'::text, 'delete'::text])));