-- +goose Up ALTER TABLE attachments DROP CONSTRAINT attachments_status_check, ADD CONSTRAINT attachments_status_check CHECK (status IN ('queued','processing','ready','failed')), DROP CONSTRAINT attachments_check, ADD CONSTRAINT attachments_check CHECK ((status='failed' AND error_code IS NOT NULL) OR (status<>'failed' AND error_code IS NULL)), ADD COLUMN variants jsonb NOT NULL DEFAULT '[]', ADD COLUMN updated_at timestamptz NOT NULL DEFAULT clock_timestamp(), ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1, ADD COLUMN staging_key text; -- +goose Down UPDATE attachments SET status='failed',error_code='pipeline_downgrade' WHERE status IN ('queued','processing'); ALTER TABLE attachments DROP CONSTRAINT attachments_status_check, ADD CONSTRAINT attachments_status_check CHECK (status IN ('ready','failed')), DROP CONSTRAINT attachments_check, ADD CONSTRAINT attachments_check CHECK ((status='ready' AND error_code IS NULL) OR (status='failed' AND error_code IS NOT NULL)), DROP COLUMN variants, DROP COLUMN updated_at, DROP COLUMN pipeline_version, DROP COLUMN staging_key;