-- CreateTable
CREATE TABLE "ListeDeroulante" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "code" TEXT NOT NULL,
    "nom" TEXT NOT NULL,
    "description" TEXT,
    "systeme" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL
);

-- CreateTable
CREATE TABLE "ItemListe" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "listeId" TEXT NOT NULL,
    "valeur" TEXT NOT NULL,
    "ordre" INTEGER NOT NULL DEFAULT 0,
    "actif" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "ItemListe_listeId_fkey" FOREIGN KEY ("listeId") REFERENCES "ListeDeroulante" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "UserCompetence" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "userId" TEXT NOT NULL,
    "itemId" TEXT NOT NULL,
    CONSTRAINT "UserCompetence_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "UserCompetence_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "ItemListe" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "ListeDeroulante_code_key" ON "ListeDeroulante"("code");

-- CreateIndex
CREATE INDEX "ItemListe_listeId_idx" ON "ItemListe"("listeId");

-- CreateIndex
CREATE INDEX "UserCompetence_userId_idx" ON "UserCompetence"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "UserCompetence_userId_itemId_key" ON "UserCompetence"("userId", "itemId");
