-- CreateTable
CREATE TABLE "TokenFleetAction" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "conversationId" TEXT NOT NULL,
    "messageId" TEXT,
    "deviceId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "payload" TEXT NOT NULL DEFAULT '{}',
    "status" TEXT NOT NULL DEFAULT 'pending',
    "result" TEXT,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "TokenFleetAction_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "TokenConversation" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_TokenMessage" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "conversationId" TEXT NOT NULL,
    "role" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "model" TEXT,
    "inputTokens" INTEGER NOT NULL DEFAULT 0,
    "outputTokens" INTEGER NOT NULL DEFAULT 0,
    "costUsd" REAL NOT NULL DEFAULT 0.0,
    "latencyMs" INTEGER NOT NULL DEFAULT 0,
    "messageType" TEXT NOT NULL DEFAULT 'chat',
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "TokenMessage_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "TokenConversation" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_TokenMessage" ("content", "conversationId", "costUsd", "createdAt", "id", "inputTokens", "latencyMs", "model", "outputTokens", "role") SELECT "content", "conversationId", "costUsd", "createdAt", "id", "inputTokens", "latencyMs", "model", "outputTokens", "role" FROM "TokenMessage";
DROP TABLE "TokenMessage";
ALTER TABLE "new_TokenMessage" RENAME TO "TokenMessage";
CREATE INDEX "TokenMessage_conversationId_idx" ON "TokenMessage"("conversationId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

-- CreateIndex
CREATE INDEX "TokenFleetAction_conversationId_idx" ON "TokenFleetAction"("conversationId");

-- CreateIndex
CREATE INDEX "TokenFleetAction_deviceId_idx" ON "TokenFleetAction"("deviceId");

-- CreateIndex
CREATE INDEX "TokenFleetAction_status_idx" ON "TokenFleetAction"("status");
