-- Add cooking preferences to User and make stripeId optional
-- SQLite requires rewriting the table for nullability changes.

PRAGMA foreign_keys=OFF;

CREATE TABLE "new_User" (
  "id" TEXT NOT NULL PRIMARY KEY,
  "email" TEXT NOT NULL,
  "password" TEXT,
  "name" TEXT NOT NULL,
  "googleId" TEXT,
  "stripeId" TEXT,
  "subscription" TEXT,
  "resetToken" TEXT,
  "resetTokenExpiry" DATETIME,
  "dietaryPreference" TEXT,
  "allergies" TEXT,
  "maxCookingTime" INTEGER,
  "equipment" TEXT,
  "cuisinePreference" TEXT,
  "servingsDefault" INTEGER,
  "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updatedAt" DATETIME NOT NULL
);

INSERT INTO "new_User" (
  "id", "email", "password", "name", "googleId", "stripeId",
  "subscription", "resetToken", "resetTokenExpiry", "createdAt", "updatedAt"
) SELECT
  "id", "email", "password", "name", "googleId", "stripeId",
  "subscription", "resetToken", "resetTokenExpiry", "createdAt", "updatedAt"
FROM "User";

DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";

CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
CREATE UNIQUE INDEX "User_googleId_key" ON "User"("googleId");
CREATE UNIQUE INDEX "User_stripeId_key" ON "User"("stripeId");

PRAGMA foreign_keys=ON;
