-- ai 0003: agent_sessions -- Generated by termix-plugin migrations. Review before committing. CREATE TABLE IF NOT EXISTS "p_ai_agent_sessions" ( "id" integer PRIMARY KEY AUTOINCREMENT, "session_id" text NOT NULL UNIQUE, "user_id" text NOT NULL, "host_id" integer NOT NULL, "provider_id" integer NOT NULL, "agent" text NOT NULL, "model" text NOT NULL, "cwd" text NOT NULL, "executable" text NOT NULL, "native_id" text, "title" text, "archived" integer NOT NULL DEFAULT 0, "queue_paused" integer NOT NULL DEFAULT 0, "draft" text, "attachments" text NOT NULL DEFAULT '[]', "updated_at" text NOT NULL, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_ai_agent_sessions_user" ON "p_ai_agent_sessions" ("user_id"); CREATE TABLE IF NOT EXISTS "p_ai_agent_events" ( "id" integer PRIMARY KEY AUTOINCREMENT, "session_id" text NOT NULL, "user_id" text NOT NULL, "seq" integer NOT NULL, "kind" text NOT NULL, "text" text NOT NULL, "request_id" text, "choices" text, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE UNIQUE INDEX IF NOT EXISTS "idx_ai_agent_events_session_seq" ON "p_ai_agent_events" ("session_id", "seq"); CREATE TABLE IF NOT EXISTS "p_ai_agent_queue" ( "id" integer PRIMARY KEY AUTOINCREMENT, "session_id" text NOT NULL, "user_id" text NOT NULL, "prompt_id" text NOT NULL, "position" integer NOT NULL, "text" text NOT NULL, "attachment_ids" text NOT NULL DEFAULT '[]', FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_ai_agent_queue_session" ON "p_ai_agent_queue" ("session_id", "position");