Files
mtusi2026lab6/migrations/000004_async_attachments.down.sql

24 lines
887 B
PL/PgSQL

BEGIN;
DROP TABLE IF EXISTS attachment_jobs;
DROP TABLE IF EXISTS attachment_variants;
ALTER TABLE attachments
DROP CONSTRAINT attachments_status_supported,
DROP CONSTRAINT attachments_status_error_consistency,
DROP CONSTRAINT attachments_staging_key_not_blank,
DROP CONSTRAINT attachments_staging_key_unique,
DROP CONSTRAINT attachments_pipeline_version_positive,
DROP COLUMN pipeline_version,
DROP COLUMN staging_key;
UPDATE attachments SET status = 'pending' WHERE status IN ('queued', 'processing');
ALTER TABLE attachments
ADD CONSTRAINT attachments_status_supported CHECK (status IN ('pending', 'ready', 'failed')),
ADD CONSTRAINT attachments_status_error_consistency CHECK (
(status = 'failed' AND error_code IS NOT NULL AND btrim(error_code) <> '')
OR (status IN ('pending', 'ready') AND error_code IS NULL)
);
COMMIT;