migration.sql 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Warnings:
  3. - Changed the type of `name` on the `exercise_attribute_names` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
  4. - Changed the type of `value` on the `exercise_attribute_values` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
  5. */
  6. -- Safe migration for exercise_attribute_names
  7. -- 1. Add temporary column with enum type
  8. ALTER TABLE "exercise_attribute_names" ADD COLUMN "name_temp" "ExerciseAttributeNameEnum";
  9. -- 2. Migrate data from text to enum (cast text to enum)
  10. UPDATE "exercise_attribute_names" SET "name_temp" = "name"::"ExerciseAttributeNameEnum";
  11. -- 3. Drop old column and rename temp column
  12. ALTER TABLE "exercise_attribute_names" DROP COLUMN "name";
  13. ALTER TABLE "exercise_attribute_names" RENAME COLUMN "name_temp" TO "name";
  14. -- 4. Set NOT NULL constraint
  15. ALTER TABLE "exercise_attribute_names" ALTER COLUMN "name" SET NOT NULL;
  16. -- Safe migration for exercise_attribute_values
  17. -- 1. Add temporary column with enum type
  18. ALTER TABLE "exercise_attribute_values" ADD COLUMN "value_temp" "ExerciseAttributeValueEnum";
  19. -- 2. Migrate data from text to enum (cast text to enum)
  20. UPDATE "exercise_attribute_values" SET "value_temp" = "value"::"ExerciseAttributeValueEnum";
  21. -- 3. Drop old column and rename temp column
  22. ALTER TABLE "exercise_attribute_values" DROP COLUMN "value";
  23. ALTER TABLE "exercise_attribute_values" RENAME COLUMN "value_temp" TO "value";
  24. -- 4. Set NOT NULL constraint
  25. ALTER TABLE "exercise_attribute_values" ALTER COLUMN "value" SET NOT NULL;
  26. -- Recreate indexes
  27. CREATE UNIQUE INDEX "exercise_attribute_names_name_key" ON "exercise_attribute_names"("name");
  28. CREATE UNIQUE INDEX "exercise_attribute_values_attributeNameId_value_key" ON "exercise_attribute_values"("attributeNameId", "value");