22 lines
1020 B
SQL
22 lines
1020 B
SQL
CREATE TABLE IF NOT EXISTS "event_outbox" (
|
|
"id" text PRIMARY KEY DEFAULT gen_random_uuid()::text NOT NULL,
|
|
"topic" text NOT NULL,
|
|
"aggregate_id" text NOT NULL,
|
|
"destination" text NOT NULL,
|
|
"payload" jsonb NOT NULL,
|
|
"headers" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
"status" text DEFAULT 'pending' NOT NULL,
|
|
"attempts" integer DEFAULT 0 NOT NULL,
|
|
"available_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"locked_at" timestamp with time zone,
|
|
"published_at" timestamp with time zone,
|
|
"last_error" text,
|
|
"response" jsonb,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "event_outbox_status_check" CHECK ("status" IN ('pending', 'processing', 'published'))
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS "event_outbox_delivery_idx" ON "event_outbox" USING btree ("status", "available_at");
|
|
CREATE UNIQUE INDEX IF NOT EXISTS "event_outbox_topic_aggregate_idx" ON "event_outbox" USING btree ("topic", "aggregate_id");
|