Files
mtusi2026lab5/src/migrations/004_pipeline.sql
T

20 lines
942 B
SQL

ALTER TABLE attachments DROP CONSTRAINT attachments_status_check;
ALTER TABLE attachments ADD CHECK (status IN ('queued', 'processing', 'ready', 'failed'));
ALTER TABLE attachments ADD COLUMN pipeline_version integer NOT NULL DEFAULT 0;
CREATE TABLE image_jobs (
id uuid PRIMARY KEY,
attachment_id uuid NOT NULL REFERENCES attachments(id),
pipeline_version integer NOT NULL CHECK (pipeline_version > 0),
attempt integer NOT NULL DEFAULT 0,
state text NOT NULL DEFAULT 'waiting' CHECK (state IN ('waiting', 'leased', 'done', 'failed')),
next_run timestamptz NOT NULL DEFAULT clock_timestamp(),
leased_until timestamptz,
published_at timestamptz,
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
trace_context jsonb NOT NULL DEFAULT '{}'::jsonb,
UNIQUE (attachment_id, pipeline_version)
);
CREATE INDEX image_jobs_pending ON image_jobs(next_run, id) WHERE state IN ('waiting', 'leased');