Files
gymflow/server/prisma/migrations/20251204191049_unify_sets/migration.sql

55 lines
2.2 KiB
SQL

/*
Warnings:
- You are about to drop the `SporadicSet` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropIndex
DROP INDEX "SporadicSet_userId_timestamp_idx";
-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "SporadicSet";
PRAGMA foreign_keys=on;
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_WorkoutSession" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"startTime" DATETIME NOT NULL,
"endTime" DATETIME,
"userBodyWeight" REAL,
"note" TEXT,
"planId" TEXT,
"planName" TEXT,
"type" TEXT NOT NULL DEFAULT 'STANDARD',
CONSTRAINT "WorkoutSession_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_WorkoutSession" ("endTime", "id", "note", "planId", "planName", "startTime", "userBodyWeight", "userId") SELECT "endTime", "id", "note", "planId", "planName", "startTime", "userBodyWeight", "userId" FROM "WorkoutSession";
DROP TABLE "WorkoutSession";
ALTER TABLE "new_WorkoutSession" RENAME TO "WorkoutSession";
CREATE TABLE "new_WorkoutSet" (
"id" TEXT NOT NULL PRIMARY KEY,
"sessionId" TEXT NOT NULL,
"exerciseId" TEXT NOT NULL,
"order" INTEGER NOT NULL,
"weight" REAL,
"reps" INTEGER,
"distanceMeters" REAL,
"durationSeconds" INTEGER,
"height" REAL,
"bodyWeightPercentage" REAL,
"completed" BOOLEAN NOT NULL DEFAULT true,
"side" TEXT,
"timestamp" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "WorkoutSet_sessionId_fkey" FOREIGN KEY ("sessionId") REFERENCES "WorkoutSession" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "WorkoutSet_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "Exercise" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_WorkoutSet" ("completed", "distanceMeters", "durationSeconds", "exerciseId", "id", "order", "reps", "sessionId", "side", "weight") SELECT "completed", "distanceMeters", "durationSeconds", "exerciseId", "id", "order", "reps", "sessionId", "side", "weight" FROM "WorkoutSet";
DROP TABLE "WorkoutSet";
ALTER TABLE "new_WorkoutSet" RENAME TO "WorkoutSet";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;