forked from mtusi2026/mtusi2026lab5
28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
DROP TABLE IF EXISTS attachment_jobs;
|
|
|
|
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_variants_array;
|
|
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_pipeline_version;
|
|
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_error_state;
|
|
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status;
|
|
|
|
-- Collapse asynchronous states back to the previous single in-flight state.
|
|
-- Ready and failed rows keep their meaning; queued/processing work is abandoned.
|
|
UPDATE attachments
|
|
SET status = 'pending', error_code = NULL
|
|
WHERE status IN ('queued', 'processing');
|
|
|
|
ALTER TABLE attachments
|
|
DROP COLUMN IF EXISTS variants,
|
|
DROP COLUMN IF EXISTS pipeline_version,
|
|
DROP COLUMN IF EXISTS staging_key,
|
|
DROP COLUMN IF EXISTS ready_at;
|
|
|
|
ALTER TABLE attachments
|
|
ADD CONSTRAINT attachments_status
|
|
CHECK (status IN ('pending', 'ready', 'failed')),
|
|
ADD CONSTRAINT attachments_error_state CHECK (
|
|
(status = 'pending' AND error_code IS NULL) OR
|
|
(status = 'ready' AND error_code IS NULL) OR
|
|
(status = 'failed' AND error_code IS NOT NULL)
|
|
);
|