-- Part 11: mapping enterprise patterns to durable rows
-- Standalone examples for DDD/domain events, projection checkpoints, and saga steps.

CREATE TABLE domain_events (
  id uuid PRIMARY KEY DEFAULT uuidv7(),
  aggregate_type text NOT NULL,
  aggregate_id text NOT NULL,
  event_type text NOT NULL,
  payload jsonb NOT NULL,
  created_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE projection_checkpoints (
  projection_name text PRIMARY KEY,
  last_event_id uuid,
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE saga_steps (
  id uuid PRIMARY KEY DEFAULT uuidv7(),
  saga_key text NOT NULL,
  step_key text NOT NULL,
  status text NOT NULL DEFAULT 'pending',
  payload jsonb NOT NULL,
  UNIQUE (saga_key, step_key)
);
