|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20240524123112 extends Migration { |
|
4
|
async up(): Promise<void> { |
|
5
|
this.addSql( |
|
6
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_email_has_account_unique" ON "customer" (email, has_account) WHERE deleted_at IS NULL;' |
|
7
|
) |
|
8
|
|
|
9
|
this.addSql( |
|
10
|
'drop index if exists "IDX_customer_address_unqiue_customer_billing";' |
|
11
|
) |
|
12
|
this.addSql( |
|
13
|
'drop index if exists "IDX_customer_address_unqiue_customer_shipping";' |
|
14
|
) |
|
15
|
this.addSql( |
|
16
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_address_unique_customer_billing" ON "customer_address" (customer_id) WHERE "is_default_billing" = true;' |
|
17
|
) |
|
18
|
this.addSql( |
|
19
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_address_unique_customer_shipping" ON "customer_address" (customer_id) WHERE "is_default_shipping" = true;' |
|
20
|
) |
|
21
|
} |
|
22
|
|
|
23
|
async down(): Promise<void> { |
|
24
|
this.addSql('drop index if exists "IDX_customer_email_has_account_unique";') |
|
25
|
|
|
26
|
this.addSql( |
|
27
|
'drop index if exists "IDX_customer_address_unique_customer_billing";' |
|
28
|
) |
|
29
|
this.addSql( |
|
30
|
'drop index if exists "IDX_customer_address_unique_customer_shipping";' |
|
31
|
) |
|
32
|
this.addSql( |
|
33
|
'create unique index if not exists "IDX_customer_address_unqiue_customer_billing" on "customer_address" ("customer_id") where "is_default_billing" = true;' |
|
34
|
) |
|
35
|
this.addSql( |
|
36
|
'create unique index if not exists "IDX_customer_address_unique_customer_shipping" on "customer_address" ("customer_id") where "is_default_shipping" = true;' |
|
37
|
) |
|
38
|
} |
|
39
|
} |