The table

CREATE TABLE adk_sessions (
  id            uuid PRIMARY KEY,
  user_id       text NOT NULL,
  agent_name    text NOT NULL,
  created_at    timestamptz NOT NULL DEFAULT now(),
  updated_at    timestamptz NOT NULL DEFAULT now(),
  status        text NOT NULL DEFAULT 'active',
  metadata      jsonb NOT NULL DEFAULT '{}'::jsonb,
  last_message  text,
  message_count int NOT NULL DEFAULT 0
);
Advertisement

Index choices

CREATE INDEX ON adk_sessions (user_id, updated_at DESC);
CREATE INDEX ON adk_sessions (status) WHERE status <> 'closed';
CREATE INDEX ON adk_sessions USING GIN (metadata);
Advertisement

Why UUID as PK

Generated client-side. No dependency on a sequence. Great for horizontally scaled write paths. Uses gen_random_uuid() in Postgres 13+.