forked from mtusi2026/mtusi2026lab7
27 lines
1.1 KiB
SQL
27 lines
1.1 KiB
SQL
ALTER TABLE attachments
|
|
DROP CONSTRAINT attachments_status_check,
|
|
DROP CONSTRAINT attachments_variants_check,
|
|
ADD COLUMN staging_key text,
|
|
ADD CONSTRAINT attachments_status_check
|
|
CHECK (status IN ('queued', 'processing', 'ready', 'failed')),
|
|
ADD CONSTRAINT attachments_variants_check
|
|
CHECK (jsonb_typeof(variants) = 'array');
|
|
|
|
CREATE TABLE attachment_jobs (
|
|
id uuid PRIMARY KEY,
|
|
attachment_id uuid NOT NULL UNIQUE REFERENCES attachments(id) ON DELETE CASCADE,
|
|
pipeline_version integer NOT NULL DEFAULT 1 CHECK (pipeline_version >= 1),
|
|
attempt integer NOT NULL DEFAULT 1 CHECK (attempt >= 1),
|
|
state text NOT NULL DEFAULT 'queued'
|
|
CHECK (state IN ('queued', 'processing', 'ready', 'failed')),
|
|
available_at timestamptz NOT NULL DEFAULT now(),
|
|
published_at timestamptz,
|
|
error_code text,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX attachment_jobs_outbox_idx
|
|
ON attachment_jobs (available_at, created_at)
|
|
WHERE state = 'queued' AND published_at IS NULL;
|