1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20241217110416 extends Migration {
4 async up(): Promise<void> {
5 this.addSql(
6 'alter table if exists "shipping_option" drop constraint if exists "shipping_option_provider_id_foreign";'
7 )
8 this.addSql(
9 'alter table if exists "shipping_option" drop constraint if exists "shipping_option_shipping_option_type_id_foreign";'
10 )
11
12 this.addSql(
13 'alter table if exists "fulfillment" drop constraint if exists "fulfillment_provider_id_foreign";'
14 )
15 this.addSql(
16 'alter table if exists "fulfillment" drop constraint if exists "fulfillment_delivery_address_id_foreign";'
17 )
18
19 this.addSql(
20 'alter table if exists "fulfillment_provider" add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
21 )
22 this.addSql(
23 'CREATE INDEX IF NOT EXISTS "IDX_fulfillment_provider_deleted_at" ON "fulfillment_provider" (deleted_at) WHERE deleted_at IS NULL;'
24 )
25
26 this.addSql(
27 'alter table if exists "shipping_option" drop constraint if exists "shipping_option_shipping_option_type_id_unique";'
28 )
29 this.addSql('drop index if exists "IDX_shipping_option_provider_id";')
30 this.addSql(
31 'drop index if exists "IDX_shipping_option_shipping_option_type_id";'
32 )
33
34 this.addSql(
35 'alter table if exists "fulfillment" drop constraint if exists "fulfillment_delivery_address_id_unique";'
36 )
37 this.addSql('drop index if exists "IDX_fulfillment_provider_id";')
38 }
39
40 async down(): Promise<void> {
41 this.addSql('drop index if exists "IDX_fulfillment_provider_deleted_at";')
42 this.addSql(
43 'alter table if exists "fulfillment_provider" drop column if exists "created_at";'
44 )
45 this.addSql(
46 'alter table if exists "fulfillment_provider" drop column if exists "updated_at";'
47 )
48 this.addSql(
49 'alter table if exists "fulfillment_provider" drop column if exists "deleted_at";'
50 )
51
52 this.addSql(
53 'alter table if exists "shipping_option" add constraint "shipping_option_provider_id_foreign" foreign key ("provider_id") references "fulfillment_provider" ("id") on update cascade on delete set null;'
54 )
55 this.addSql(
56 'alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_foreign" foreign key ("shipping_option_type_id") references "shipping_option_type" ("id") on update cascade on delete cascade;'
57 )
58 this.addSql(
59 'alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_unique" unique ("shipping_option_type_id");'
60 )
61 this.addSql(
62 'CREATE INDEX IF NOT EXISTS "IDX_shipping_option_provider_id" ON "shipping_option" (provider_id) WHERE deleted_at IS NULL;'
63 )
64 this.addSql(
65 'CREATE INDEX IF NOT EXISTS "IDX_shipping_option_shipping_option_type_id" ON "shipping_option" (shipping_option_type_id) WHERE deleted_at IS NULL;'
66 )
67
68 this.addSql(
69 'alter table if exists "fulfillment" add constraint "fulfillment_provider_id_foreign" foreign key ("provider_id") references "fulfillment_provider" ("id") on update cascade on delete set null;'
70 )
71 this.addSql(
72 'alter table if exists "fulfillment" add constraint "fulfillment_delivery_address_id_foreign" foreign key ("delivery_address_id") references "fulfillment_address" ("id") on update cascade on delete cascade;'
73 )
74 this.addSql(
75 'alter table if exists "fulfillment" add constraint "fulfillment_delivery_address_id_unique" unique ("delivery_address_id");'
76 )
77 this.addSql(
78 'CREATE INDEX IF NOT EXISTS "IDX_fulfillment_provider_id" ON "fulfillment" (provider_id) WHERE deleted_at IS NULL;'
79 )
80 }
81 }