Files
mtusi2026lab5/migrations/008_async_attachments.sql
T
2026-11-16 09:28:38 +03:00

22 lines
947 B
SQL

-- Keep existing lab4 originals ready; new jobs set queued explicitly.
ALTER TABLE attachments DROP CONSTRAINT attachments_status_check;
ALTER TABLE attachments
ADD CONSTRAINT attachments_status_check
CHECK (status IN ('queued', 'processing', 'ready', 'failed')),
ADD COLUMN variants jsonb NOT NULL DEFAULT '[]'::jsonb
CHECK (jsonb_typeof(variants) = 'array');
CREATE TABLE jobs (
id uuid PRIMARY KEY,
attachment_id uuid NOT NULL UNIQUE
REFERENCES attachments(id) ON DELETE CASCADE,
status text NOT NULL DEFAULT 'queued'
CHECK (status IN ('queued', 'processing', 'ready', 'failed')),
retries integer NOT NULL DEFAULT 0 CHECK (retries >= 0),
error_code text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX jobs_status_created_at_idx ON jobs (status, created_at);