fix(customer): Unique constraint on customer email (#7439)
**What** Prevent creating multiple customers with the same email
This commit is contained in:
@@ -124,6 +124,14 @@
|
||||
"name": "customer",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_customer_email_has_account_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_email_has_account_unique\" ON \"customer\" (email, has_account) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "customer_pkey",
|
||||
"columnNames": [
|
||||
@@ -321,20 +329,20 @@
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_customer_address_unqiue_customer_billing",
|
||||
"keyName": "IDX_customer_address_unique_customer_billing",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "create unique index \"IDX_customer_address_unqiue_customer_billing\" on \"customer_address\" (\"customer_id\") where \"is_default_billing\" = true"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_billing\" ON \"customer_address\" (customer_id) WHERE \"is_default_billing\" = true"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_customer_address_unqiue_customer_shipping",
|
||||
"keyName": "IDX_customer_address_unique_customer_shipping",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "create unique index \"IDX_customer_address_unique_customer_shipping\" on \"customer_address\" (\"customer_id\") where \"is_default_shipping\" = true"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_customer_address_unique_customer_shipping\" ON \"customer_address\" (customer_id) WHERE \"is_default_shipping\" = true"
|
||||
},
|
||||
{
|
||||
"keyName": "customer_address_pkey",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20240524123112 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_email_has_account_unique" ON "customer" (email, has_account) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('drop index if exists "IDX_customer_address_unqiue_customer_billing";');
|
||||
this.addSql('drop index if exists "IDX_customer_address_unqiue_customer_shipping";');
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_address_unique_customer_billing" ON "customer_address" (customer_id) WHERE "is_default_billing" = true;');
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_customer_address_unique_customer_shipping" ON "customer_address" (customer_id) WHERE "is_default_shipping" = true;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_customer_email_has_account_unique";');
|
||||
|
||||
this.addSql('drop index if exists "IDX_customer_address_unique_customer_billing";');
|
||||
this.addSql('drop index if exists "IDX_customer_address_unique_customer_shipping";');
|
||||
this.addSql('create unique index if not exists "IDX_customer_address_unqiue_customer_billing" on "customer_address" ("customer_id") where "is_default_billing" = true;');
|
||||
this.addSql('create unique index if not exists "IDX_customer_address_unique_customer_shipping" on "customer_address" ("customer_id") where "is_default_shipping" = true;');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user