Files
mtusi2026lab6/migrations/007_replay_audit.sql
T

17 lines
843 B
SQL

-- A replay starts a new bounded run without deleting earlier outbox history.
ALTER TABLE attachment_jobs
ADD COLUMN replay_start_attempt integer NOT NULL DEFAULT 1
CHECK (replay_start_attempt > 0 AND replay_start_attempt <= attempt);
CREATE TABLE attachment_job_replays (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
job_id uuid NOT NULL REFERENCES attachment_jobs(id) ON DELETE CASCADE,
previous_attempt integer NOT NULL CHECK (previous_attempt > 0),
new_attempt integer NOT NULL CHECK (new_attempt > previous_attempt),
previous_error_code text NOT NULL,
operator_name text NOT NULL CHECK (length(operator_name) BETWEEN 1 AND 80),
reason text NOT NULL CHECK (length(reason) BETWEEN 1 AND 200),
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
UNIQUE (job_id, new_attempt)
);