forked from mtusi2026/mtusi2026lab5
lab5 na4
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
ALTER TABLE attachments ADD COLUMN staging_key TEXT;
|
||||
ALTER TABLE attachments ADD COLUMN variants JSONB NOT NULL DEFAULT '[]';
|
||||
ALTER TABLE attachments ADD COLUMN error_code TEXT;
|
||||
ALTER TABLE attachments ADD CONSTRAINT attachment_status CHECK (status IN ('queued','processing','ready','failed'));
|
||||
|
||||
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 0,
|
||||
status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued','processing','ready','failed')),
|
||||
lease_token UUID,
|
||||
lease_until TIMESTAMPTZ,
|
||||
next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
error_code TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX job_recovery ON attachment_jobs(lease_until) WHERE status = 'processing';
|
||||
CREATE TABLE attachment_outbox (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
job_id UUID NOT NULL REFERENCES attachment_jobs(id) ON DELETE CASCADE,
|
||||
attempt INTEGER NOT NULL,
|
||||
available_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
published_at TIMESTAMPTZ
|
||||
);
|
||||
CREATE INDEX outbox_pending ON attachment_outbox(available_at, id) WHERE published_at IS NULL;
|
||||
CREATE TABLE job_replays (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
job_id UUID NOT NULL REFERENCES attachment_jobs(id),
|
||||
reason TEXT NOT NULL CHECK (length(reason) BETWEEN 1 AND 200),
|
||||
previous_attempt INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
Reference in New Issue
Block a user