|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20241205095237 extends Migration { |
|
4
|
async up(): Promise<void> { |
|
5
|
this.addSql( |
|
6
|
'alter table if exists "cart_line_item" drop constraint if exists "cart_line_item_cart_id_foreign";' |
|
7
|
) |
|
8
|
|
|
9
|
this.addSql( |
|
10
|
'alter table if exists "cart_line_item_adjustment" drop constraint if exists "cart_line_item_adjustment_item_id_foreign";' |
|
11
|
) |
|
12
|
|
|
13
|
this.addSql( |
|
14
|
'alter table if exists "cart_line_item_tax_line" drop constraint if exists "cart_line_item_tax_line_item_id_foreign";' |
|
15
|
) |
|
16
|
|
|
17
|
this.addSql( |
|
18
|
'alter table if exists "cart_shipping_method" drop constraint if exists "cart_shipping_method_cart_id_foreign";' |
|
19
|
) |
|
20
|
|
|
21
|
this.addSql( |
|
22
|
'alter table if exists "cart_line_item" alter column "requires_shipping" type boolean using ("requires_shipping"::boolean);' |
|
23
|
) |
|
24
|
this.addSql( |
|
25
|
'alter table if exists "cart_line_item" alter column "requires_shipping" set default true;' |
|
26
|
) |
|
27
|
this.addSql( |
|
28
|
'alter table if exists "cart_line_item" alter column "is_discountable" type boolean using ("is_discountable"::boolean);' |
|
29
|
) |
|
30
|
this.addSql( |
|
31
|
'alter table if exists "cart_line_item" alter column "is_discountable" set default true;' |
|
32
|
) |
|
33
|
this.addSql( |
|
34
|
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' |
|
35
|
) |
|
36
|
this.addSql( |
|
37
|
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" set default false;' |
|
38
|
) |
|
39
|
this.addSql( |
|
40
|
'alter table if exists "cart_line_item" add constraint "cart_line_item_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade on delete cascade;' |
|
41
|
) |
|
42
|
this.addSql( |
|
43
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_cart_id" ON "cart_line_item" (cart_id) WHERE deleted_at IS NULL;' |
|
44
|
) |
|
45
|
|
|
46
|
this.addSql( |
|
47
|
'alter table if exists "cart_line_item_adjustment" add constraint "cart_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade on delete cascade;' |
|
48
|
) |
|
49
|
this.addSql( |
|
50
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_adjustment_item_id" ON "cart_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;' |
|
51
|
) |
|
52
|
|
|
53
|
this.addSql( |
|
54
|
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade on delete cascade;' |
|
55
|
) |
|
56
|
this.addSql( |
|
57
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_tax_line_item_id" ON "cart_line_item_tax_line" (item_id) WHERE deleted_at IS NULL;' |
|
58
|
) |
|
59
|
|
|
60
|
this.addSql( |
|
61
|
'alter table if exists "cart_shipping_method" add constraint "cart_shipping_method_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade on delete cascade;' |
|
62
|
) |
|
63
|
this.addSql( |
|
64
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_cart_id" ON "cart_shipping_method" (cart_id) WHERE deleted_at IS NULL;' |
|
65
|
) |
|
66
|
|
|
67
|
this.addSql( |
|
68
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_adjustment_shipping_method_id" ON "cart_shipping_method_adjustment" (shipping_method_id) WHERE deleted_at IS NULL;' |
|
69
|
) |
|
70
|
this.addSql( |
|
71
|
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_tax_line_shipping_method_id" ON "cart_shipping_method_tax_line" (shipping_method_id) WHERE deleted_at IS NULL;' |
|
72
|
) |
|
73
|
} |
|
74
|
|
|
75
|
async down(): Promise<void> { |
|
76
|
this.addSql( |
|
77
|
'alter table if exists "cart_line_item" drop constraint if exists "cart_line_item_cart_id_foreign";' |
|
78
|
) |
|
79
|
|
|
80
|
this.addSql( |
|
81
|
'alter table if exists "cart_line_item_adjustment" drop constraint if exists "cart_line_item_adjustment_item_id_foreign";' |
|
82
|
) |
|
83
|
|
|
84
|
this.addSql( |
|
85
|
'alter table if exists "cart_line_item_tax_line" drop constraint if exists "cart_line_item_tax_line_item_id_foreign";' |
|
86
|
) |
|
87
|
|
|
88
|
this.addSql( |
|
89
|
'alter table if exists "cart_shipping_method" drop constraint if exists "cart_shipping_method_cart_id_foreign";' |
|
90
|
) |
|
91
|
|
|
92
|
this.addSql( |
|
93
|
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" drop default;' |
|
94
|
) |
|
95
|
this.addSql( |
|
96
|
'alter table if exists "cart_line_item" alter column "is_tax_inclusive" type boolean using ("is_tax_inclusive"::boolean);' |
|
97
|
) |
|
98
|
this.addSql('drop index if exists "IDX_cart_line_item_cart_id";') |
|
99
|
this.addSql( |
|
100
|
'alter table if exists "cart_line_item" add constraint "cart_line_item_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade;' |
|
101
|
) |
|
102
|
|
|
103
|
this.addSql('drop index if exists "IDX_cart_line_item_adjustment_item_id";') |
|
104
|
this.addSql( |
|
105
|
'alter table if exists "cart_line_item_adjustment" add constraint "cart_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;' |
|
106
|
) |
|
107
|
|
|
108
|
this.addSql('drop index if exists "IDX_cart_line_item_tax_line_item_id";') |
|
109
|
this.addSql( |
|
110
|
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;' |
|
111
|
) |
|
112
|
|
|
113
|
this.addSql('drop index if exists "IDX_cart_shipping_method_cart_id";') |
|
114
|
this.addSql( |
|
115
|
'alter table if exists "cart_shipping_method" add constraint "cart_shipping_method_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade;' |
|
116
|
) |
|
117
|
|
|
118
|
this.addSql( |
|
119
|
'drop index if exists "IDX_cart_shipping_method_adjustment_shipping_method_id";' |
|
120
|
) |
|
121
|
|
|
122
|
this.addSql( |
|
123
|
'drop index if exists "IDX_cart_shipping_method_tax_line_shipping_method_id";' |
|
124
|
) |
|
125
|
} |
|
126
|
} |