stock-bot/database/postgres/init/15-canonical-paper-intents.sql

13 lines
698 B
SQL

-- All owners at one financial revision commit one immutable native decision batch.
-- Native order IDs are retained verbatim in checkpoints/journals, not legacy UUID tables.
CREATE TABLE IF NOT EXISTS simulation_canonical_intents (
account_id TEXT NOT NULL REFERENCES simulation_accounts(id),
id TEXT NOT NULL,
sequence BIGINT NOT NULL CHECK (sequence > 0),
status TEXT NOT NULL CHECK (status IN ('pending', 'dispatched', 'failed')),
payload JSONB NOT NULL,
PRIMARY KEY (account_id, id),
UNIQUE (account_id, sequence)
);
CREATE INDEX IF NOT EXISTS simulation_canonical_intents_pending
ON simulation_canonical_intents(account_id, sequence) WHERE status = 'pending';