/*
  Warnings:

  - You are about to drop the column `botId` on the `ChatState` table. All the data in the column will be lost.
  - A unique constraint covering the columns `[platform,originalPlatformId]` on the table `User` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `externalBotId` to the `ChatState` table without a default value. This is not possible if the table is not empty.

*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_ChatState" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "userId" TEXT NOT NULL,
    "externalBotId" TEXT NOT NULL,
    "stateJson" JSONB NOT NULL,
    "lockedByBot" BOOLEAN NOT NULL DEFAULT false,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "ChatState_externalBotId_fkey" FOREIGN KEY ("externalBotId") REFERENCES "ExternalBot" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_ChatState" ("id", "lockedByBot", "stateJson", "updatedAt", "userId") SELECT "id", "lockedByBot", "stateJson", "updatedAt", "userId" FROM "ChatState";
DROP TABLE "ChatState";
ALTER TABLE "new_ChatState" RENAME TO "ChatState";
CREATE UNIQUE INDEX "ChatState_userId_externalBotId_key" ON "ChatState"("userId", "externalBotId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

-- CreateIndex
CREATE UNIQUE INDEX "User_platform_originalPlatformId_key" ON "User"("platform", "originalPlatformId");
