-- CreateEnum
CREATE TYPE "ProjektStatus" AS ENUM ('Aktiv', 'Abgeschlossen');

-- CreateTable
CREATE TABLE "projekte" (
    "id" TEXT NOT NULL,
    "titel" TEXT NOT NULL,
    "auftraggeber" TEXT,
    "datum" DATE,
    "monteur" TEXT,
    "notiz" TEXT,
    "status" "ProjektStatus" NOT NULL DEFAULT 'Aktiv',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "projekte_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "material" (
    "id" TEXT NOT NULL,
    "projektId" TEXT NOT NULL,
    "bezeichnung" TEXT NOT NULL,
    "artNr" TEXT,
    "menge" DECIMAL(10,2) NOT NULL,
    "einheit" TEXT NOT NULL,
    "notiz" TEXT,
    "erstelltVon" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "material_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "material_projektId_idx" ON "material"("projektId");

-- AddForeignKey
ALTER TABLE "material" ADD CONSTRAINT "material_projektId_fkey" FOREIGN KEY ("projektId") REFERENCES "projekte"("id") ON DELETE CASCADE ON UPDATE CASCADE;
