/*
  Warnings:

  - You are about to drop the column `lastExpAt` on the `VillageObject` table. All the data in the column will be lost.
  - You are about to drop the column `clearingStartedAt` on the `VillageTile` table. All the data in the column will be lost.

*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_VillageObject" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "type" TEXT NOT NULL,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "lastExpDay" TEXT,
    "cropType" TEXT,
    "plantedAt" DATETIME,
    "villageId" INTEGER NOT NULL,
    "tileId" INTEGER NOT NULL,
    CONSTRAINT "VillageObject_villageId_fkey" FOREIGN KEY ("villageId") REFERENCES "Village" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "VillageObject_tileId_fkey" FOREIGN KEY ("tileId") REFERENCES "VillageTile" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_VillageObject" ("createdAt", "cropType", "id", "lastExpDay", "plantedAt", "tileId", "type", "villageId") SELECT "createdAt", "cropType", "id", "lastExpDay", "plantedAt", "tileId", "type", "villageId" FROM "VillageObject";
DROP TABLE "VillageObject";
ALTER TABLE "new_VillageObject" RENAME TO "VillageObject";
CREATE UNIQUE INDEX "VillageObject_tileId_key" ON "VillageObject"("tileId");
CREATE TABLE "new_VillageTile" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "x" INTEGER NOT NULL,
    "y" INTEGER NOT NULL,
    "terrainType" TEXT NOT NULL,
    "terrainState" TEXT NOT NULL DEFAULT 'IDLE',
    "clearingStartedDay" TEXT,
    "villageId" INTEGER NOT NULL,
    CONSTRAINT "VillageTile_villageId_fkey" FOREIGN KEY ("villageId") REFERENCES "Village" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_VillageTile" ("clearingStartedDay", "id", "terrainState", "terrainType", "villageId", "x", "y") SELECT "clearingStartedDay", "id", "terrainState", "terrainType", "villageId", "x", "y" FROM "VillageTile";
DROP TABLE "VillageTile";
ALTER TABLE "new_VillageTile" RENAME TO "VillageTile";
CREATE UNIQUE INDEX "VillageTile_villageId_x_y_key" ON "VillageTile"("villageId", "x", "y");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
