-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_BotSession" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "userId" TEXT NOT NULL,
    "threadTs" TEXT NOT NULL,
    "channel" TEXT NOT NULL,
    "sessionId" TEXT,
    "workdir" TEXT,
    "containerName" TEXT,
    "model" TEXT NOT NULL DEFAULT 'opus',
    "provider" TEXT NOT NULL DEFAULT 'direct',
    "summary" TEXT,
    "persistUntil" DATETIME,
    "totalCost" REAL NOT NULL DEFAULT 0,
    "totalInput" INTEGER NOT NULL DEFAULT 0,
    "totalOutput" INTEGER NOT NULL DEFAULT 0,
    "messageCount" INTEGER NOT NULL DEFAULT 0,
    "warned1" BOOLEAN NOT NULL DEFAULT false,
    "warned2" BOOLEAN NOT NULL DEFAULT false,
    "persistWarned" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "lastActivity" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "BotSession_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_BotSession" ("channel", "containerName", "createdAt", "id", "lastActivity", "messageCount", "model", "persistUntil", "provider", "sessionId", "summary", "threadTs", "totalCost", "totalInput", "totalOutput", "userId", "workdir") SELECT "channel", "containerName", "createdAt", "id", "lastActivity", "messageCount", "model", "persistUntil", "provider", "sessionId", "summary", "threadTs", "totalCost", "totalInput", "totalOutput", "userId", "workdir" FROM "BotSession";
DROP TABLE "BotSession";
ALTER TABLE "new_BotSession" RENAME TO "BotSession";
CREATE UNIQUE INDEX "BotSession_threadTs_key" ON "BotSession"("threadTs");
CREATE INDEX "BotSession_userId_idx" ON "BotSession"("userId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
