CREATE TABLE summary_generations ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, summary_id UUID REFERENCES summaries(id) ON DELETE SET NULL, outcome JSONB NOT NULL CHECK (jsonb_typeof(outcome) = 'object'), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); CREATE INDEX summary_generations_user_created_idx ON summary_generations (user_id, created_at DESC);