forked from mtusi2026/mtusi2026lab5
lab5
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
ALTER TABLE attachments DROP CONSTRAINT attachments_status_check;
|
||||
UPDATE attachments SET status='failed',error_code='legacy_incomplete' WHERE status IN ('uploading','missing');
|
||||
ALTER TABLE attachments ADD CONSTRAINT attachments_status_check CHECK (status IN ('queued','processing','ready','failed'));
|
||||
ALTER TABLE attachments ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1 CHECK (pipeline_version>0);
|
||||
ALTER TABLE attachments ADD COLUMN variants jsonb NOT NULL DEFAULT '[]';
|
||||
ALTER TABLE attachments ADD COLUMN variant_keys jsonb NOT NULL DEFAULT '{}';
|
||||
|
||||
CREATE TABLE jobs (
|
||||
id uuid PRIMARY KEY,
|
||||
attachment_id uuid NOT NULL REFERENCES attachments(id),
|
||||
pipeline_version integer NOT NULL CHECK (pipeline_version>0),
|
||||
status text NOT NULL CHECK (status IN ('queued','processing','ready','failed','superseded')),
|
||||
staging_key text NOT NULL UNIQUE,
|
||||
attempts integer NOT NULL DEFAULT 0,
|
||||
budget_start integer NOT NULL DEFAULT 0,
|
||||
available_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
lease_until timestamptz,
|
||||
lease_token uuid,
|
||||
error_code text,
|
||||
staged_deleted_at timestamptz,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
UNIQUE (attachment_id,pipeline_version)
|
||||
);
|
||||
ALTER TABLE attachments ADD COLUMN current_job_id uuid REFERENCES jobs(id);
|
||||
CREATE INDEX jobs_schedule_idx ON jobs(status,available_at);
|
||||
CREATE TABLE job_outbox (
|
||||
id bigserial PRIMARY KEY,
|
||||
job_id uuid NOT NULL REFERENCES jobs(id),
|
||||
attempt integer NOT NULL CHECK (attempt>0),
|
||||
published_at timestamptz,
|
||||
stream_id text,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
UNIQUE (job_id,attempt)
|
||||
);
|
||||
CREATE INDEX job_outbox_pending_idx ON job_outbox(id) WHERE published_at IS NULL;
|
||||
CREATE TABLE job_events (
|
||||
id bigserial PRIMARY KEY,
|
||||
job_id uuid NOT NULL REFERENCES jobs(id),
|
||||
event text NOT NULL,
|
||||
details jsonb NOT NULL DEFAULT '{}',
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||||
);
|
||||
-- Точечные одноразовые сбои нужны для воспроизводимого эксперимента трека 2.
|
||||
-- Исполнение разрешено только с ALLOW_FAULT_INJECTION=1; UUID конкретной job обязателен.
|
||||
CREATE TABLE pipeline_faults (
|
||||
job_id uuid NOT NULL REFERENCES jobs(id),
|
||||
phase text NOT NULL,
|
||||
fired_at timestamptz,
|
||||
PRIMARY KEY (job_id,phase)
|
||||
);
|
||||
CREATE TABLE broker_rejections (
|
||||
stream_id text PRIMARY KEY,
|
||||
sha256 char(64) NOT NULL,
|
||||
error_code text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||||
);
|
||||
Reference in New Issue
Block a user