-- +goose Up ALTER TABLE attachment_jobs ADD COLUMN published_original_key TEXT CHECK (length(published_original_key) > 0); UPDATE attachment_jobs AS j SET published_original_key = a.object_key FROM attachments AS a WHERE a.id = j.attachment_id AND a.pipeline_version = j.pipeline_version AND a.status = 'ready'; CREATE INDEX attachment_jobs_published_original_idx ON attachment_jobs (published_original_key) WHERE published_original_key IS NOT NULL; ALTER TABLE attachment_attempts DROP CONSTRAINT attachment_attempts_outcome_check, ADD CONSTRAINT attachment_attempts_outcome_check CHECK (outcome IN ('ready', 'retry', 'failed', 'lease_expired', 'superseded')); -- +goose Down UPDATE attachment_attempts SET outcome = 'failed' WHERE outcome = 'superseded'; ALTER TABLE attachment_attempts DROP CONSTRAINT attachment_attempts_outcome_check, ADD CONSTRAINT attachment_attempts_outcome_check CHECK (outcome IN ('ready', 'retry', 'failed', 'lease_expired')); ALTER TABLE attachment_jobs DROP COLUMN published_original_key;