/*
  Warnings:

  - You are about to drop the `Kauf_Artikel` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "Kauf_Artikel";
PRAGMA foreign_keys=on;

-- CreateTable
CREATE TABLE "KaufArtikel" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "kauf_id" INTEGER NOT NULL,
    "artikel_id" INTEGER NOT NULL,
    "anzahl" INTEGER NOT NULL,
    CONSTRAINT "KaufArtikel_kauf_id_fkey" FOREIGN KEY ("kauf_id") REFERENCES "Kauf" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "KaufArtikel_artikel_id_fkey" FOREIGN KEY ("artikel_id") REFERENCES "Artikel" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Kategorie" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "timestamp" INTEGER NOT NULL,
    "preis_ges" REAL
);

-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Artikel" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "preis" REAL,
    "kategorie_id" INTEGER,
    CONSTRAINT "Artikel_kategorie_id_fkey" FOREIGN KEY ("kategorie_id") REFERENCES "Kategorie" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Artikel" ("id", "name", "preis") SELECT "id", "name", "preis" FROM "Artikel";
DROP TABLE "Artikel";
ALTER TABLE "new_Artikel" RENAME TO "Artikel";
CREATE UNIQUE INDEX "Artikel_name_key" ON "Artikel"("name");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;

-- CreateIndex
CREATE UNIQUE INDEX "Kategorie_name_key" ON "Kategorie"("name");
