-- Multi-User-Umbau mit Fresh-Start: bestehende Testdaten werden verworfen
-- (abgestimmt am 11.07.2026). Household haengt neu an einem User-Konto.

-- Bestehende Daten loeschen (Cascade raeumt Persons, Plans, Phases, ... mit ab)
DELETE FROM "Household";
DROP TABLE "AppCredential";

-- CreateTable
CREATE TABLE "User" (
    "id" TEXT NOT NULL,
    "username" TEXT NOT NULL,
    "passwordHash" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");

-- AlterTable (Tabelle ist leer, daher NOT NULL ohne Default moeglich)
ALTER TABLE "Household" ADD COLUMN "userId" TEXT NOT NULL;

-- AddForeignKey
ALTER TABLE "Household" ADD CONSTRAINT "Household_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
