-- V3-Rework: Das Grundprofil (Haushaltsform, Personen, Inflation) wandert vom Household
-- auf die Plan-Ebene. Bestehende Plaene/Personen sind ohne Household-Bezug bzw. ohne die
-- neuen Pflichtfelder nicht migrierbar -- die (disponiblen) Testdaten werden verworfen.
TRUNCATE TABLE "Person", "Plan" CASCADE;

-- DropForeignKey
ALTER TABLE "Household" DROP CONSTRAINT "Household_userId_fkey";

-- DropForeignKey
ALTER TABLE "Person" DROP CONSTRAINT "Person_householdId_fkey";

-- DropForeignKey
ALTER TABLE "Plan" DROP CONSTRAINT "Plan_householdId_fkey";

-- DropIndex
DROP INDEX "Person_householdId_role_key";

-- AlterTable
ALTER TABLE "Person" DROP COLUMN "householdId",
ADD COLUMN     "planId" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "Plan" DROP COLUMN "householdId",
DROP COLUMN "retirementAgeA",
DROP COLUMN "retirementAgeB",
ADD COLUMN     "householdType" "HouseholdType" NOT NULL,
ADD COLUMN     "inflationRateDefault" DOUBLE PRECISION NOT NULL,
ADD COLUMN     "userId" TEXT NOT NULL;

-- DropTable
DROP TABLE "Household";

-- CreateIndex
CREATE UNIQUE INDEX "Person_planId_role_key" ON "Person"("planId", "role");

-- AddForeignKey
ALTER TABLE "Person" ADD CONSTRAINT "Person_planId_fkey" FOREIGN KEY ("planId") REFERENCES "Plan"("id") ON DELETE CASCADE ON UPDATE CASCADE;

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