migration.sql 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Warnings:
  3. - You are about to drop the `WorkoutSession` table. If the table is not empty, all the data it contains will be lost.
  4. - You are about to drop the `WorkoutSessionExercise` table. If the table is not empty, all the data it contains will be lost.
  5. - You are about to drop the `WorkoutSet` table. If the table is not empty, all the data it contains will be lost.
  6. */
  7. -- DropForeignKey
  8. ALTER TABLE "WorkoutSession" DROP CONSTRAINT "WorkoutSession_userId_fkey";
  9. -- DropForeignKey
  10. ALTER TABLE "WorkoutSessionExercise" DROP CONSTRAINT "WorkoutSessionExercise_exerciseId_fkey";
  11. -- DropForeignKey
  12. ALTER TABLE "WorkoutSessionExercise" DROP CONSTRAINT "WorkoutSessionExercise_workoutSessionId_fkey";
  13. -- DropForeignKey
  14. ALTER TABLE "WorkoutSet" DROP CONSTRAINT "WorkoutSet_workoutSessionExerciseId_fkey";
  15. -- DropTable
  16. DROP TABLE "WorkoutSession";
  17. -- DropTable
  18. DROP TABLE "WorkoutSessionExercise";
  19. -- DropTable
  20. DROP TABLE "WorkoutSet";
  21. -- CreateTable
  22. CREATE TABLE "workout_sessions" (
  23. "id" TEXT NOT NULL,
  24. "userId" TEXT NOT NULL,
  25. "startedAt" TIMESTAMP(3) NOT NULL,
  26. "endedAt" TIMESTAMP(3),
  27. "duration" INTEGER,
  28. CONSTRAINT "workout_sessions_pkey" PRIMARY KEY ("id")
  29. );
  30. -- CreateTable
  31. CREATE TABLE "workout_session_exercises" (
  32. "id" TEXT NOT NULL,
  33. "workoutSessionId" TEXT NOT NULL,
  34. "exerciseId" TEXT NOT NULL,
  35. "order" INTEGER NOT NULL,
  36. CONSTRAINT "workout_session_exercises_pkey" PRIMARY KEY ("id")
  37. );
  38. -- CreateTable
  39. CREATE TABLE "workout_sets" (
  40. "id" TEXT NOT NULL,
  41. "workoutSessionExerciseId" TEXT NOT NULL,
  42. "setIndex" INTEGER NOT NULL,
  43. "type" "WorkoutSetType" NOT NULL,
  44. "types" "WorkoutSetType"[] DEFAULT ARRAY[]::"WorkoutSetType"[],
  45. "valueInt" INTEGER,
  46. "valuesInt" INTEGER[] DEFAULT ARRAY[]::INTEGER[],
  47. "valueSec" INTEGER,
  48. "valuesSec" INTEGER[] DEFAULT ARRAY[]::INTEGER[],
  49. "unit" "WorkoutSetUnit",
  50. "units" "WorkoutSetUnit"[] DEFAULT ARRAY[]::"WorkoutSetUnit"[],
  51. "completed" BOOLEAN NOT NULL DEFAULT false,
  52. CONSTRAINT "workout_sets_pkey" PRIMARY KEY ("id")
  53. );
  54. -- AddForeignKey
  55. ALTER TABLE "workout_sessions" ADD CONSTRAINT "workout_sessions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  56. -- AddForeignKey
  57. 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;
  58. -- AddForeignKey
  59. ALTER TABLE "workout_session_exercises" ADD CONSTRAINT "workout_session_exercises_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  60. -- AddForeignKey
  61. ALTER TABLE "workout_sets" ADD CONSTRAINT "workout_sets_workoutSessionExerciseId_fkey" FOREIGN KEY ("workoutSessionExerciseId") REFERENCES "workout_session_exercises"("id") ON DELETE RESTRICT ON UPDATE CASCADE;