railyard/apps/ledgerline/migrations/0002_settlement_outbox.sql
caelum0x 894359e5ff feat(railyard): per-app completion pass — money-correct settlement + crate cores
- rago: exactly-once prepaid settlement (deterministic idempotency, unique partial index + in-tx ON CONFLICT guard) — closes the double-charge risk
- mint: double-entry + reserve conservation verified (14 tests)
- ledgerline: atomic settlement outbox + partial recovery index (37 tests)
- abacus: hard per-agent budget enforcement + kill-switch (54 tests)
- vend: crash reaper / in-flight session reconciliation
- turnstile/agent-runtime/ranguard/rit/game-economy/context-passport/rithub: core advanced + tests
2026-09-07 17:17:54 +03:00

20 lines
967 B
SQL

-- Crash-visible progress for the Mint hold/capture/COGS settlement saga.
CREATE TABLE IF NOT EXISTS settlement_outbox (
request_id TEXT PRIMARY KEY,
event_json TEXT NOT NULL,
attempt BIGINT NOT NULL CHECK (attempt > 0 AND attempt <= 4294967295),
state TEXT NOT NULL CHECK (state IN ('pending', 'settled', 'compensating', 'compensated')),
hold_state TEXT NOT NULL CHECK (hold_state IN ('pending', 'committed', 'compensated')),
hold_id TEXT,
hold_seq BIGINT,
capture_state TEXT NOT NULL CHECK (capture_state IN ('pending', 'committed', 'compensated')),
revenue_seq BIGINT,
cogs_state TEXT NOT NULL CHECK (cogs_state IN ('pending', 'committed', 'compensated')),
cogs_seq BIGINT,
updated_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX IF NOT EXISTS settlement_outbox_recovery
ON settlement_outbox (state, updated_at)
WHERE state IN ('pending', 'compensating');