forked from mtusi2026/mtusi2026lab5
22 lines
947 B
SQL
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);
|