Add PostgreSQL DurableStore substrate for WP-03
Introduce remora-durable with pool/migrations, a RemoraApiMutation-shaped ledger, claim-fenced outbox projection, CAS helpers, and keyset cursors, plus a kind Job acceptance suite against the hermetic fixture.
This commit is contained in:
parent
af8bb1a03a
commit
957d170150
1 changed files with 3203 additions and 18 deletions
38
crates/remora-durable/migrations/0001_substrate.sql
Normal file
38
crates/remora-durable/migrations/0001_substrate.sql
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
-- DurableStore substrate tables owned by remora-durable.
|
||||
-- Feature packages add their own migrations; they do not alter these tables.
|
||||
|
||||
CREATE TABLE mutation_records (
|
||||
scope_subject TEXT NOT NULL,
|
||||
scope_operation TEXT NOT NULL,
|
||||
operation_key TEXT NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
-- Opaque RemoraApiMutation eligibility / authority binding (attempt, fence,
|
||||
-- worker incarnation, or other claim material). Compared for exact replay.
|
||||
eligibility_claim BYTEA NOT NULL,
|
||||
request_fingerprint BYTEA NOT NULL CHECK (octet_length(request_fingerprint) = 32),
|
||||
response_status TEXT NOT NULL CHECK (response_status IN ('accepted', 'rejected')),
|
||||
response_body JSONB NOT NULL,
|
||||
effect_applied BOOLEAN NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (scope_subject, scope_operation, operation_key),
|
||||
CHECK (effect_applied = (response_status = 'accepted'))
|
||||
);
|
||||
|
||||
CREATE TABLE outbox_messages (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
topic TEXT NOT NULL,
|
||||
payload JSONB NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
available_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
claimed_by TEXT,
|
||||
claimed_until TIMESTAMPTZ,
|
||||
-- Monotonic per-row claim epoch; with claimed_by forms the ownership token.
|
||||
claim_generation BIGINT NOT NULL DEFAULT 0,
|
||||
projected_at TIMESTAMPTZ,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 0,
|
||||
last_error TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX outbox_messages_claimable_idx
|
||||
ON outbox_messages (available_at, id)
|
||||
WHERE projected_at IS NULL;
|
||||
Loading…
Reference in a new issue