Bladeren bron

chore/table map (#16)

Mat B. 1 maand geleden
bovenliggende
commit
d5a31a3b64
4 gewijzigde bestanden met toevoegingen van 101 en 1 verwijderingen
  1. 3 1
      package.json
  2. 13 0
      pnpm-lock.yaml
  3. 79 0
      prisma/migrations/20250614125347_add_table_maps/migration.sql
  4. 6 0
      prisma/schema.prisma

+ 3 - 1
package.json

@@ -13,7 +13,8 @@
     "postinstall": "prisma generate",
     "lint": "next lint",
     "import:exercises-full": "tsx scripts/import-exercises-with-attributes.ts",
-    "db:seed": "pnpm run import:exercises-full ./data/sample-exercises.csv"
+    "db:seed": "pnpm run import:exercises-full ./data/sample-exercises.csv",
+    "migrate:prod": "env-cmd -f .env.production prisma migrate deploy"
   },
   "resolutions": {
     "prettier": "^3.4.2"
@@ -135,6 +136,7 @@
     "@typescript-eslint/parser": "^8.29.0",
     "autoprefixer": "^10.4.21",
     "daisyui": "^5.0.43",
+    "env-cmd": "^10.1.0",
     "eslint": "^9.23.0",
     "eslint-config-next": "15.2.3",
     "eslint-plugin-import": "^2.31.0",

+ 13 - 0
pnpm-lock.yaml

@@ -354,6 +354,9 @@ importers:
       daisyui:
         specifier: ^5.0.43
         version: 5.0.43
+      env-cmd:
+        specifier: ^10.1.0
+        version: 10.1.0
       eslint:
         specifier: ^9.23.0
         version: 9.29.0(jiti@2.4.2)
@@ -3101,6 +3104,11 @@ packages:
     resolution: {integrity: sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==}
     engines: {node: '>=0.12'}
 
+  env-cmd@10.1.0:
+    resolution: {integrity: sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==}
+    engines: {node: '>=8.0.0'}
+    hasBin: true
+
   es-abstract@1.24.0:
     resolution: {integrity: sha512-WSzPgsdLtTcQwm4CROfS5ju2Wa1QQcVeT37jFjYzdFz1r9ahadC8B8/a4qxJxM+09F18iumCdRmlr96ZYkQvEg==}
     engines: {node: '>= 0.4'}
@@ -8332,6 +8340,11 @@ snapshots:
 
   entities@6.0.1: {}
 
+  env-cmd@10.1.0:
+    dependencies:
+      commander: 4.1.1
+      cross-spawn: 7.0.6
+
   es-abstract@1.24.0:
     dependencies:
       array-buffer-byte-length: 1.0.2

+ 79 - 0
prisma/migrations/20250614125347_add_table_maps/migration.sql

@@ -0,0 +1,79 @@
+/*
+  Warnings:
+
+  - You are about to drop the `WorkoutSession` table. If the table is not empty, all the data it contains will be lost.
+  - You are about to drop the `WorkoutSessionExercise` table. If the table is not empty, all the data it contains will be lost.
+  - You are about to drop the `WorkoutSet` table. If the table is not empty, all the data it contains will be lost.
+
+*/
+-- DropForeignKey
+ALTER TABLE "WorkoutSession" DROP CONSTRAINT "WorkoutSession_userId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "WorkoutSessionExercise" DROP CONSTRAINT "WorkoutSessionExercise_exerciseId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "WorkoutSessionExercise" DROP CONSTRAINT "WorkoutSessionExercise_workoutSessionId_fkey";
+
+-- DropForeignKey
+ALTER TABLE "WorkoutSet" DROP CONSTRAINT "WorkoutSet_workoutSessionExerciseId_fkey";
+
+-- DropTable
+DROP TABLE "WorkoutSession";
+
+-- DropTable
+DROP TABLE "WorkoutSessionExercise";
+
+-- DropTable
+DROP TABLE "WorkoutSet";
+
+-- CreateTable
+CREATE TABLE "workout_sessions" (
+    "id" TEXT NOT NULL,
+    "userId" TEXT NOT NULL,
+    "startedAt" TIMESTAMP(3) NOT NULL,
+    "endedAt" TIMESTAMP(3),
+    "duration" INTEGER,
+
+    CONSTRAINT "workout_sessions_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "workout_session_exercises" (
+    "id" TEXT NOT NULL,
+    "workoutSessionId" TEXT NOT NULL,
+    "exerciseId" TEXT NOT NULL,
+    "order" INTEGER NOT NULL,
+
+    CONSTRAINT "workout_session_exercises_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "workout_sets" (
+    "id" TEXT NOT NULL,
+    "workoutSessionExerciseId" TEXT NOT NULL,
+    "setIndex" INTEGER NOT NULL,
+    "type" "WorkoutSetType" NOT NULL,
+    "types" "WorkoutSetType"[] DEFAULT ARRAY[]::"WorkoutSetType"[],
+    "valueInt" INTEGER,
+    "valuesInt" INTEGER[] DEFAULT ARRAY[]::INTEGER[],
+    "valueSec" INTEGER,
+    "valuesSec" INTEGER[] DEFAULT ARRAY[]::INTEGER[],
+    "unit" "WorkoutSetUnit",
+    "units" "WorkoutSetUnit"[] DEFAULT ARRAY[]::"WorkoutSetUnit"[],
+    "completed" BOOLEAN NOT NULL DEFAULT false,
+
+    CONSTRAINT "workout_sets_pkey" PRIMARY KEY ("id")
+);
+
+-- AddForeignKey
+ALTER TABLE "workout_sessions" ADD CONSTRAINT "workout_sessions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "workout_session_exercises" ADD CONSTRAINT "workout_session_exercises_workoutSessionId_fkey" FOREIGN KEY ("workoutSessionId") REFERENCES "workout_sessions"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "workout_session_exercises" ADD CONSTRAINT "workout_session_exercises_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "workout_sets" ADD CONSTRAINT "workout_sets_workoutSessionExerciseId_fkey" FOREIGN KEY ("workoutSessionExerciseId") REFERENCES "workout_session_exercises"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

+ 6 - 0
prisma/schema.prisma

@@ -274,6 +274,8 @@ model WorkoutSession {
   endedAt   DateTime?
   duration  Int? // en secondes
   exercises WorkoutSessionExercise[]
+
+  @@map("workout_sessions")
 }
 
 model WorkoutSessionExercise {
@@ -284,6 +286,8 @@ model WorkoutSessionExercise {
   workoutSession   WorkoutSession @relation(fields: [workoutSessionId], references: [id])
   exercise         Exercise       @relation(fields: [exerciseId], references: [id])
   sets             WorkoutSet[]
+
+  @@map("workout_session_exercises")
 }
 
 model WorkoutSet {
@@ -300,6 +304,8 @@ model WorkoutSet {
   units                    WorkoutSetUnit[]       @default([])
   completed                Boolean                @default(false)
   workoutSessionExercise   WorkoutSessionExercise @relation(fields: [workoutSessionExerciseId], references: [id])
+
+  @@map("workout_sets")
 }
 
 enum WorkoutSetType {