Files
mtusi2026lab7/migrations/004_attachment_jobs.sql
T
dmice9 9bf101b322
Application / https-smoke (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Implement Lab 7 service security
2026-12-03 20:56:06 +03:00

22 lines
945 B
SQL

ALTER TABLE attachments
ADD COLUMN status text NOT NULL DEFAULT 'queued'
CHECK (status IN ('queued', 'processing', 'ready', 'failed')),
ADD COLUMN variants jsonb NOT NULL DEFAULT '[]',
ADD COLUMN error_code text,
ADD CHECK ((status = 'failed') = (error_code IS NOT NULL));
CREATE TABLE attachment_jobs (
id uuid PRIMARY KEY,
attachment_id uuid NOT NULL UNIQUE REFERENCES attachments(id),
source_key text NOT NULL,
attempts integer NOT NULL DEFAULT 0 CHECK (attempts >= 0),
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
publish_at timestamptz DEFAULT clock_timestamp()
);
CREATE INDEX attachment_jobs_pending_idx ON attachment_jobs(publish_at, id)
WHERE publish_at IS NOT NULL;
-- Existing Lab 4 originals can be used as input without copying or deleting them.
INSERT INTO attachment_jobs(id, attachment_id, source_key)
SELECT gen_random_uuid(), id, object_key FROM attachments;