Перенести реализацию лабораторной 5 в лабораторную 6
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
-- Lab5: the database owns the work intent; RabbitMQ carries only its IDs.
|
||||
ALTER TABLE attachments DROP CONSTRAINT attachments_status_check;
|
||||
ALTER TABLE attachments ADD CONSTRAINT attachments_status_check
|
||||
CHECK (status IN ('queued', 'processing', 'ready', 'failed'));
|
||||
ALTER TABLE attachments
|
||||
ADD COLUMN staging_key TEXT,
|
||||
ADD COLUMN pipeline_version INTEGER NOT NULL DEFAULT 1 CHECK (pipeline_version = 1),
|
||||
ADD COLUMN job_id UUID UNIQUE,
|
||||
ADD COLUMN attempt INTEGER NOT NULL DEFAULT 1 CHECK (attempt >= 1),
|
||||
ADD COLUMN attempts_run INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN lease_token UUID,
|
||||
ADD COLUMN lease_until TIMESTAMPTZ,
|
||||
ADD COLUMN next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
ADD COLUMN staging_deleted BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN variants JSONB NOT NULL DEFAULT '[]'::jsonb;
|
||||
|
||||
CREATE TABLE outbox (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
job_id UUID NOT NULL,
|
||||
attachment_id UUID NOT NULL REFERENCES attachments(id),
|
||||
attempt INTEGER NOT NULL DEFAULT 1,
|
||||
available_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
published_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX outbox_pending_idx ON outbox(available_at, id) WHERE published_at IS NULL;
|
||||
CREATE INDEX attachments_lease_idx ON attachments(lease_until) WHERE status = 'processing';
|
||||
CREATE INDEX attachments_staging_idx ON attachments(updated_at)
|
||||
WHERE staging_key IS NOT NULL AND NOT staging_deleted;
|
||||
|
||||
-- Failed registry = attachments WHERE status='failed'. This append-only
|
||||
-- journal explains retry, lease recovery and explicit operator replay.
|
||||
CREATE TABLE job_events (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
attachment_id UUID NOT NULL REFERENCES attachments(id),
|
||||
event TEXT NOT NULL,
|
||||
attempt INTEGER NOT NULL,
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX job_events_attachment_idx ON job_events(attachment_id, id);
|
||||
|
||||
-- Internal one-shot crash injection, never exposed through public HTTP.
|
||||
CREATE TABLE fault_injections (
|
||||
point TEXT PRIMARY KEY,
|
||||
remaining INTEGER NOT NULL DEFAULT 0 CHECK (remaining >= 0),
|
||||
hits INTEGER NOT NULL DEFAULT 0,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
Reference in New Issue
Block a user