From d309d06970b314331d88c4765ab807e8901bb1c7 Mon Sep 17 00:00:00 2001 From: luciano Date: Wed, 29 Apr 2026 12:35:14 +0200 Subject: [PATCH] feat(db): add initial migration creating users, profiles, preferences Generated by `prisma migrate dev --name init` against the local Postgres. Creates the 6 enums and the 3 tables with their unique indexes and foreign keys (profiles.user_id and preferences.user_id with ON DELETE CASCADE). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../20260429103340_init/migration.sql | 77 +++++++++++++++++++ .../db/prisma/migrations/migration_lock.toml | 3 + 2 files changed, 80 insertions(+) create mode 100644 packages/db/prisma/migrations/20260429103340_init/migration.sql create mode 100644 packages/db/prisma/migrations/migration_lock.toml diff --git a/packages/db/prisma/migrations/20260429103340_init/migration.sql b/packages/db/prisma/migrations/20260429103340_init/migration.sql new file mode 100644 index 0000000..1b0568c --- /dev/null +++ b/packages/db/prisma/migrations/20260429103340_init/migration.sql @@ -0,0 +1,77 @@ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('USER', 'COACH'); + +-- CreateEnum +CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE', 'OTHER'); + +-- CreateEnum +CREATE TYPE "ActivityLevel" AS ENUM ('SEDENTARY', 'LIGHT', 'MODERATE', 'INTENSE'); + +-- CreateEnum +CREATE TYPE "Phase" AS ENUM ('INTENSIVE', 'TRANSITION', 'MAINTENANCE'); + +-- CreateEnum +CREATE TYPE "CookingTime" AS ENUM ('LOW', 'MEDIUM', 'HIGH'); + +-- CreateEnum +CREATE TYPE "FastingProtocol" AS ENUM ('FOURTEEN_TEN', 'SIXTEEN_EIGHT', 'EIGHTEEN_SIX', 'TWENTY_FOUR', 'ESE_24', 'FIVE_TWO'); + +-- CreateTable +CREATE TABLE "users" ( + "id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "role" "Role" NOT NULL DEFAULT 'USER', + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "users_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "profiles" ( + "id" TEXT NOT NULL, + "user_id" TEXT NOT NULL, + "age" INTEGER NOT NULL, + "gender" "Gender" NOT NULL, + "height_cm" INTEGER NOT NULL, + "weight_start_kg" DECIMAL(5,2) NOT NULL, + "weight_current_kg" DECIMAL(5,2) NOT NULL, + "weight_goal_kg" DECIMAL(5,2) NOT NULL, + "activity_level" "ActivityLevel" NOT NULL, + "target_date" DATE, + "current_phase" "Phase" NOT NULL DEFAULT 'INTENSIVE', + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "profiles_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "preferences" ( + "id" TEXT NOT NULL, + "user_id" TEXT NOT NULL, + "exclusions" TEXT[] DEFAULT ARRAY[]::TEXT[], + "cuisine_preferences" TEXT[] DEFAULT ARRAY[]::TEXT[], + "cooking_time" "CookingTime" NOT NULL DEFAULT 'MEDIUM', + "fasting_protocol" "FastingProtocol", + "notification_settings" JSONB NOT NULL DEFAULT '{}', + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "preferences_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "profiles_user_id_key" ON "profiles"("user_id"); + +-- CreateIndex +CREATE UNIQUE INDEX "preferences_user_id_key" ON "preferences"("user_id"); + +-- AddForeignKey +ALTER TABLE "profiles" ADD CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "preferences" ADD CONSTRAINT "preferences_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/db/prisma/migrations/migration_lock.toml b/packages/db/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/packages/db/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file