-- AlterTable
-- SQLite ne supporte pas directement le changement de type, donc on doit recréer la table
-- On convertit les dates string ISO en datetime

-- Créer une nouvelle table avec le bon type
CREATE TABLE "Event_new" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "date" DATETIME NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "status" TEXT NOT NULL,
    "room" TEXT,
    "time" TEXT,
    "maxPlaces" INTEGER,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL
);

-- Copier les données en convertissant les dates string en datetime
INSERT INTO "Event_new" ("id", "date", "name", "description", "type", "status", "room", "time", "maxPlaces", "createdAt", "updatedAt")
SELECT 
    "id",
    datetime("date") as "date",
    "name",
    "description",
    "type",
    "status",
    "room",
    "time",
    "maxPlaces",
    "createdAt",
    "updatedAt"
FROM "Event";

-- Supprimer l'ancienne table
DROP TABLE "Event";

-- Renommer la nouvelle table
ALTER TABLE "Event_new" RENAME TO "Event";

-- Recréer les index
CREATE INDEX "Event_status_idx" ON "Event"("status");
CREATE INDEX "Event_date_idx" ON "Event"("date");

