-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from WhyAsh5114/117-fix-incorrect-bodyweight
fix: update bodyweight type to include decimals as well
- Loading branch information
Showing
5 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
prisma/migrations/20241015125503_change_bodyweight_to_decimal_type/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Warnings: | ||
- Changed the type of `userBodyweight` on the `Workout` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
*/ | ||
|
||
-- Step 1: Add a new column with the DECIMAL type | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
ADD COLUMN "newUserBodyweight" DECIMAL(5, 2); | ||
COMMIT; | ||
|
||
-- Step 2: Migrate the existing data from the old column to the new one | ||
BEGIN; | ||
UPDATE "Workout" | ||
SET "newUserBodyweight" = CAST("userBodyweight" AS DECIMAL(5, 2)); | ||
COMMIT; | ||
|
||
-- Step 3: Ensure no null values exist in the new column before making it required | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
ALTER COLUMN "newUserBodyweight" SET NOT NULL; | ||
COMMIT; | ||
|
||
-- Step 4: Drop the old column | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
DROP COLUMN "userBodyweight"; | ||
COMMIT; | ||
|
||
-- Step 5: Rename the new column to the original name | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
RENAME COLUMN "newUserBodyweight" TO "userBodyweight"; | ||
COMMIT; |
37 changes: 37 additions & 0 deletions
37
prisma/migrations/20241015132840_change_bodyweight_to_float_for_now/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Warnings: | ||
- Changed the type of `userBodyweight` on the `Workout` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
*/ | ||
|
||
-- Step 1: Add a new column with the FLOAT type | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
ADD COLUMN "tempUserBodyweight" FLOAT; | ||
COMMIT; | ||
|
||
-- Step 2: Migrate the existing data from DECIMAL(5, 2) to FLOAT | ||
BEGIN; | ||
UPDATE "Workout" | ||
SET "tempUserBodyweight" = "userBodyweight"; | ||
COMMIT; | ||
|
||
-- Step 3: Ensure no null values exist in the new column before making it required | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
ALTER COLUMN "tempUserBodyweight" SET NOT NULL; | ||
COMMIT; | ||
|
||
-- Step 4: Drop the DECIMAL column | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
DROP COLUMN "userBodyweight"; | ||
COMMIT; | ||
|
||
-- Step 5: Rename the new column to the original name | ||
BEGIN; | ||
ALTER TABLE "Workout" | ||
RENAME COLUMN "tempUserBodyweight" TO "userBodyweight"; | ||
COMMIT; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters