CREATE TABLE IF NOT EXISTS command_idempotency (
  composite_key TEXT PRIMARY KEY,
  user_id TEXT NOT NULL,
  route TEXT NOT NULL,
  idempotency_key TEXT NOT NULL,
  status_code INTEGER NOT NULL,
  response_payload JSONB NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  expires_at TIMESTAMPTZ NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_command_idempotency_expires_at
  ON command_idempotency (expires_at);
