-- 025_agent_groups.sql — Automations workspace (phase 1): user-defined -- groups and the original natural-language prompt stored alongside the -- compiled spec (editing recompiles through the same compile endpoint). -- -- Additive and idempotent; schema.sql carries the identical shape, so this -- is a structural no-op on a fresh database (db-converge proves both paths -- land the same). Deleting a group ungroups its tasks (FK SET NULL) — it -- never deletes automations. The engine is untouched: groupId/prompt are -- metadata; the spec jsonb remains the only thing it executes. CREATE TABLE IF NOT EXISTS "AgentGroup" ( id text PRIMARY KEY, "ownerId" text NOT NULL REFERENCES "User"(id) ON DELETE CASCADE, name text NOT NULL, position integer NOT NULL DEFAULT 0, version integer NOT NULL DEFAULT 1, "createdAt" timestamptz NOT NULL DEFAULT now(), "updatedAt" timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS "AgentGroup_ownerId_idx" ON "AgentGroup"("ownerId"); ALTER TABLE "AgentTask" ADD COLUMN IF NOT EXISTS "groupId" text REFERENCES "AgentGroup"(id) ON DELETE SET NULL; ALTER TABLE "AgentTask" ADD COLUMN IF NOT EXISTS prompt text NOT NULL DEFAULT ''; CREATE INDEX IF NOT EXISTS "AgentTask_groupId_idx" ON "AgentTask"("groupId");