|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20241211074630 extends Migration { |
|
4
|
async up(): Promise<void> { |
|
5
|
this.addSql( |
|
6
|
'alter table if exists "customer_group_customer" drop constraint if exists "customer_group_customer_customer_group_id_foreign";' |
|
7
|
) |
|
8
|
this.addSql( |
|
9
|
'alter table if exists "customer_group_customer" drop constraint if exists "customer_group_customer_customer_id_foreign";' |
|
10
|
) |
|
11
|
|
|
12
|
this.addSql( |
|
13
|
'CREATE INDEX IF NOT EXISTS "IDX_customer_deleted_at" ON "customer" (deleted_at) WHERE deleted_at IS NULL;' |
|
14
|
) |
|
15
|
|
|
16
|
this.addSql( |
|
17
|
'alter table if exists "customer_address" add column if not exists "deleted_at" timestamptz null;' |
|
18
|
) |
|
19
|
this.addSql( |
|
20
|
'CREATE INDEX IF NOT EXISTS "IDX_customer_address_deleted_at" ON "customer_address" (deleted_at) WHERE deleted_at IS NULL;' |
|
21
|
) |
|
22
|
|
|
23
|
this.addSql( |
|
24
|
'CREATE INDEX IF NOT EXISTS "IDX_customer_group_deleted_at" ON "customer_group" (deleted_at) WHERE deleted_at IS NULL;' |
|
25
|
) |
|
26
|
|
|
27
|
this.addSql( |
|
28
|
'alter table if exists "customer_group_customer" add column if not exists "deleted_at" timestamptz null;' |
|
29
|
) |
|
30
|
this.addSql('drop index if exists "IDX_customer_group_customer_group_id";') |
|
31
|
this.addSql( |
|
32
|
'alter table if exists "customer_group_customer" add constraint "customer_group_customer_customer_group_id_foreign" foreign key ("customer_group_id") references "customer_group" ("id") on update cascade on delete cascade;' |
|
33
|
) |
|
34
|
this.addSql( |
|
35
|
'alter table if exists "customer_group_customer" add constraint "customer_group_customer_customer_id_foreign" foreign key ("customer_id") references "customer" ("id") on update cascade on delete cascade;' |
|
36
|
) |
|
37
|
|
|
38
|
this.addSql( |
|
39
|
'CREATE INDEX IF NOT EXISTS "IDX_customer_group_customer_customer_group_id" ON "customer_group_customer" (customer_group_id) WHERE deleted_at IS NULL;' |
|
40
|
) |
|
41
|
this.addSql( |
|
42
|
'CREATE INDEX IF NOT EXISTS "IDX_customer_group_customer_deleted_at" ON "customer_group_customer" (deleted_at) WHERE deleted_at IS NULL;' |
|
43
|
) |
|
44
|
} |
|
45
|
|
|
46
|
async down(): Promise<void> { |
|
47
|
this.addSql('drop index if exists "IDX_customer_deleted_at";') |
|
48
|
|
|
49
|
this.addSql('drop index if exists "IDX_customer_address_deleted_at";') |
|
50
|
this.addSql( |
|
51
|
'alter table if exists "customer_address" drop column if exists "deleted_at";' |
|
52
|
) |
|
53
|
|
|
54
|
this.addSql('drop index if exists "IDX_customer_group_deleted_at";') |
|
55
|
|
|
56
|
this.addSql( |
|
57
|
'drop index if exists "IDX_customer_group_customer_customer_group_id";' |
|
58
|
) |
|
59
|
this.addSql( |
|
60
|
'drop index if exists "IDX_customer_group_customer_deleted_at";' |
|
61
|
) |
|
62
|
this.addSql( |
|
63
|
'alter table if exists "customer_group_customer" drop column if exists "deleted_at";' |
|
64
|
) |
|
65
|
this.addSql( |
|
66
|
'create index if not exists "IDX_customer_group_customer_group_id" on "customer_group_customer" ("customer_group_id");' |
|
67
|
) |
|
68
|
} |
|
69
|
} |