Files
buryan-infra/ops/events/schema.sql
T
architect 46761c0142
lint / hygiene (pull_request) Failing after 28s
standard / check (pull_request) Successful in 12s
lint / hygiene (push) Failing after 2m3s
standard / check (push) Successful in 27s
[STAGE2] Durable events pipeline + Audit360 adapter
2026-11-27 11:17:39 +03:00

56 lines
1.9 KiB
SQL

-- Stage 2 event fabric: outbox/inbox/effects
CREATE SCHEMA IF NOT EXISTS events;
CREATE TABLE IF NOT EXISTS events.outbox (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
event_id text NOT NULL UNIQUE,
specversion text NOT NULL DEFAULT '1.0',
source text NOT NULL,
type text NOT NULL,
subject text,
time timestamptz NOT NULL,
datacontenttype text NOT NULL DEFAULT 'application/json',
idempotency_key text NOT NULL UNIQUE,
correlation_id text,
causation_id text,
payload jsonb NOT NULL,
status text NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending','published','failed')),
attempts integer NOT NULL DEFAULT 0,
last_error text,
created_at timestamptz NOT NULL DEFAULT now(),
published_at timestamptz
);
CREATE INDEX IF NOT EXISTS outbox_pending_idx
ON events.outbox (status, created_at);
CREATE TABLE IF NOT EXISTS events.inbox (
id bigserial PRIMARY KEY,
consumer text NOT NULL,
event_id text NOT NULL,
idempotency_key text NOT NULL,
payload jsonb NOT NULL,
status text NOT NULL DEFAULT 'processed'
CHECK (status IN ('processed','failed')),
received_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (consumer, event_id)
);
CREATE INDEX IF NOT EXISTS inbox_key_idx
ON events.inbox (idempotency_key);
CREATE TABLE IF NOT EXISTS events.adapter_state (
adapter text PRIMARY KEY,
cursor text,
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS events.effects (
idempotency_key text PRIMARY KEY,
consumer text NOT NULL,
effect_type text NOT NULL,
result jsonb NOT NULL DEFAULT '{}'::jsonb,
created_at timestamptz NOT NULL DEFAULT now()
);