|
| 1 | +import { Migration } from '@mikro-orm/migrations'; |
| 2 | + |
| 3 | +export class Migration20250103192244_idNumberToUuid extends Migration { |
| 4 | + |
| 5 | + override async up(): Promise<void> { |
| 6 | + this.addSql(`alter table "exercise" drop constraint "exercise_exercise_type_id_foreign";`); |
| 7 | + this.addSql(`alter table "exercise" drop constraint "exercise_video_id_foreign";`); |
| 8 | + |
| 9 | + this.addSql(`alter table "exercise_type" alter column "id" drop default;`); |
| 10 | + this.addSql(`alter table "exercise_type" alter column "id" type uuid using ("id"::text::uuid);`); |
| 11 | + this.addSql(`alter table "exercise_type" alter column "id" set default gen_random_uuid();`); |
| 12 | + |
| 13 | + this.addSql(`alter table "test" alter column "id" drop default;`); |
| 14 | + this.addSql(`alter table "test" alter column "id" type uuid using ("id"::text::uuid);`); |
| 15 | + this.addSql(`alter table "test" alter column "id" set default gen_random_uuid();`); |
| 16 | + |
| 17 | + this.addSql(`alter table "video" alter column "id" drop default;`); |
| 18 | + this.addSql(`alter table "video" alter column "id" type uuid using ("id"::text::uuid);`); |
| 19 | + this.addSql(`alter table "video" alter column "id" set default gen_random_uuid();`); |
| 20 | + |
| 21 | + this.addSql(`alter table "exercise" alter column "id" drop default;`); |
| 22 | + this.addSql(`alter table "exercise" alter column "id" type uuid using ("id"::text::uuid);`); |
| 23 | + this.addSql(`alter table "exercise" alter column "id" set default gen_random_uuid();`); |
| 24 | + this.addSql(`alter table "exercise" alter column "exercise_type_id" drop default;`); |
| 25 | + this.addSql(`alter table "exercise" alter column "exercise_type_id" type uuid using ("exercise_type_id"::text::uuid);`); |
| 26 | + this.addSql(`alter table "exercise" alter column "video_id" drop default;`); |
| 27 | + this.addSql(`alter table "exercise" alter column "video_id" type uuid using ("video_id"::text::uuid);`); |
| 28 | + this.addSql(`alter table "exercise" add constraint "exercise_exercise_type_id_foreign" foreign key ("exercise_type_id") references "exercise_type" ("id") on update cascade;`); |
| 29 | + this.addSql(`alter table "exercise" add constraint "exercise_video_id_foreign" foreign key ("video_id") references "video" ("id") on update cascade on delete set null;`); |
| 30 | + } |
| 31 | + |
| 32 | + override async down(): Promise<void> { |
| 33 | + this.addSql(`alter table "exercise_type" alter column "id" type text using ("id"::text);`); |
| 34 | + |
| 35 | + this.addSql(`alter table "test" alter column "id" type text using ("id"::text);`); |
| 36 | + |
| 37 | + this.addSql(`alter table "video" alter column "id" type text using ("id"::text);`); |
| 38 | + |
| 39 | + this.addSql(`alter table "exercise" alter column "id" type text using ("id"::text);`); |
| 40 | + this.addSql(`alter table "exercise" alter column "exercise_type_id" type text using ("exercise_type_id"::text);`); |
| 41 | + this.addSql(`alter table "exercise" alter column "video_id" type text using ("video_id"::text);`); |
| 42 | + |
| 43 | + this.addSql(`alter table "exercise" drop constraint "exercise_exercise_type_id_foreign";`); |
| 44 | + this.addSql(`alter table "exercise" drop constraint "exercise_video_id_foreign";`); |
| 45 | + |
| 46 | + this.addSql(`alter table "exercise_type" alter column "id" drop default;`); |
| 47 | + this.addSql(`alter table "exercise_type" alter column "id" type int using ("id"::int);`); |
| 48 | + this.addSql(`create sequence if not exists "exercise_type_id_seq";`); |
| 49 | + this.addSql(`select setval('exercise_type_id_seq', (select max("id") from "exercise_type"));`); |
| 50 | + this.addSql(`alter table "exercise_type" alter column "id" set default nextval('exercise_type_id_seq');`); |
| 51 | + |
| 52 | + this.addSql(`alter table "test" alter column "id" drop default;`); |
| 53 | + this.addSql(`alter table "test" alter column "id" type int using ("id"::int);`); |
| 54 | + this.addSql(`create sequence if not exists "test_id_seq";`); |
| 55 | + this.addSql(`select setval('test_id_seq', (select max("id") from "test"));`); |
| 56 | + this.addSql(`alter table "test" alter column "id" set default nextval('test_id_seq');`); |
| 57 | + |
| 58 | + this.addSql(`alter table "video" alter column "id" drop default;`); |
| 59 | + this.addSql(`alter table "video" alter column "id" type int using ("id"::int);`); |
| 60 | + this.addSql(`create sequence if not exists "video_id_seq";`); |
| 61 | + this.addSql(`select setval('video_id_seq', (select max("id") from "video"));`); |
| 62 | + this.addSql(`alter table "video" alter column "id" set default nextval('video_id_seq');`); |
| 63 | + |
| 64 | + this.addSql(`alter table "exercise" alter column "id" drop default;`); |
| 65 | + this.addSql(`alter table "exercise" alter column "id" type int using ("id"::int);`); |
| 66 | + this.addSql(`alter table "exercise" alter column "exercise_type_id" type int using ("exercise_type_id"::int);`); |
| 67 | + this.addSql(`alter table "exercise" alter column "video_id" type int using ("video_id"::int);`); |
| 68 | + this.addSql(`create sequence if not exists "exercise_id_seq";`); |
| 69 | + this.addSql(`select setval('exercise_id_seq', (select max("id") from "exercise"));`); |
| 70 | + this.addSql(`alter table "exercise" alter column "id" set default nextval('exercise_id_seq');`); |
| 71 | + this.addSql(`alter table "exercise" add constraint "exercise_exercise_type_id_foreign" foreign key ("exercise_type_id") references "exercise_type" ("id") on update cascade;`); |
| 72 | + this.addSql(`alter table "exercise" add constraint "exercise_video_id_foreign" foreign key ("video_id") references "video" ("id") on update cascade on delete set null;`); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments