fix: Unique constraint should account for soft deleted records (#11048)
FIXES FRMW-2878 **What** Currently, the `one-to-one` unique constraints does not account for deleted record. This prevents from inserting a new record wth the same fk if another one is deleted. **Caveat** `hasOne` with FK option is meant to be a special case, for example a many to one - one to many without defining the other side of the relation. In that case we don't handle this behaviour and keep it as it is
This commit is contained in:
committed by
GitHub
parent
ecc8efcb04
commit
da3906efa4
@@ -309,24 +309,6 @@
|
||||
"name": "cart",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"shipping_address_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "cart_shipping_address_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"columnNames": [
|
||||
"billing_address_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "cart_billing_address_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_cart_deleted_at",
|
||||
"columnNames": [],
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250120115059 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "cart" drop constraint if exists "cart_shipping_address_id_unique";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "cart" drop constraint if exists "cart_billing_address_id_unique";'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "cart" add constraint "cart_shipping_address_id_unique" unique ("shipping_address_id");'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "cart" add constraint "cart_billing_address_id_unique" unique ("billing_address_id");'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"namespaces": ["public"],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
@@ -161,9 +159,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_address_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -242,9 +238,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_provider_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -349,9 +343,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_set_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -465,9 +457,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "service_zone_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -478,13 +468,9 @@
|
||||
"foreignKeys": {
|
||||
"service_zone_fulfillment_set_id_foreign": {
|
||||
"constraintName": "service_zone_fulfillment_set_id_foreign",
|
||||
"columnNames": [
|
||||
"fulfillment_set_id"
|
||||
],
|
||||
"columnNames": ["fulfillment_set_id"],
|
||||
"localTableName": "public.service_zone",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_set",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -511,12 +497,7 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'country'",
|
||||
"enumItems": [
|
||||
"country",
|
||||
"province",
|
||||
"city",
|
||||
"zip"
|
||||
],
|
||||
"enumItems": ["country", "province", "city", "zip"],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"country_code": {
|
||||
@@ -656,9 +637,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "geo_zone_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -669,13 +648,9 @@
|
||||
"foreignKeys": {
|
||||
"geo_zone_service_zone_id_foreign": {
|
||||
"constraintName": "geo_zone_service_zone_id_foreign",
|
||||
"columnNames": [
|
||||
"service_zone_id"
|
||||
],
|
||||
"columnNames": ["service_zone_id"],
|
||||
"localTableName": "public.geo_zone",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.service_zone",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -768,9 +743,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_type_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -875,9 +848,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_profile_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -916,10 +887,7 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'flat'",
|
||||
"enumItems": [
|
||||
"calculated",
|
||||
"flat"
|
||||
],
|
||||
"enumItems": ["calculated", "flat"],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"data": {
|
||||
@@ -1013,9 +981,7 @@
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"shipping_option_type_id"
|
||||
],
|
||||
"columnNames": ["shipping_option_type_id"],
|
||||
"composite": false,
|
||||
"keyName": "shipping_option_shipping_option_type_id_unique",
|
||||
"constraint": true,
|
||||
@@ -1060,9 +1026,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -1073,52 +1037,36 @@
|
||||
"foreignKeys": {
|
||||
"shipping_option_service_zone_id_foreign": {
|
||||
"constraintName": "shipping_option_service_zone_id_foreign",
|
||||
"columnNames": [
|
||||
"service_zone_id"
|
||||
],
|
||||
"columnNames": ["service_zone_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.service_zone",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_shipping_profile_id_foreign": {
|
||||
"constraintName": "shipping_option_shipping_profile_id_foreign",
|
||||
"columnNames": [
|
||||
"shipping_profile_id"
|
||||
],
|
||||
"columnNames": ["shipping_profile_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.shipping_profile",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_provider_id_foreign": {
|
||||
"constraintName": "shipping_option_provider_id_foreign",
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"columnNames": ["provider_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_shipping_option_type_id_foreign": {
|
||||
"constraintName": "shipping_option_shipping_option_type_id_foreign",
|
||||
"columnNames": [
|
||||
"shipping_option_type_id"
|
||||
],
|
||||
"columnNames": ["shipping_option_type_id"],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.shipping_option_type",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
@@ -1152,16 +1100,7 @@
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"enumItems": [
|
||||
"in",
|
||||
"eq",
|
||||
"ne",
|
||||
"gt",
|
||||
"gte",
|
||||
"lt",
|
||||
"lte",
|
||||
"nin"
|
||||
],
|
||||
"enumItems": ["in", "eq", "ne", "gt", "gte", "lt", "lte", "nin"],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"value": {
|
||||
@@ -1238,9 +1177,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "shipping_option_rule_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -1251,13 +1188,9 @@
|
||||
"foreignKeys": {
|
||||
"shipping_option_rule_shipping_option_id_foreign": {
|
||||
"constraintName": "shipping_option_rule_shipping_option_id_foreign",
|
||||
"columnNames": [
|
||||
"shipping_option_id"
|
||||
],
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"localTableName": "public.shipping_option_rule",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.shipping_option",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -1435,9 +1368,7 @@
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"columnNames": ["provider_id"],
|
||||
"composite": false,
|
||||
"keyName": "fulfillment_provider_id_unique",
|
||||
"constraint": true,
|
||||
@@ -1445,9 +1376,7 @@
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"columnNames": [
|
||||
"delivery_address_id"
|
||||
],
|
||||
"columnNames": ["delivery_address_id"],
|
||||
"composite": false,
|
||||
"keyName": "fulfillment_delivery_address_id_unique",
|
||||
"constraint": true,
|
||||
@@ -1483,9 +1412,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -1496,39 +1423,27 @@
|
||||
"foreignKeys": {
|
||||
"fulfillment_provider_id_foreign": {
|
||||
"constraintName": "fulfillment_provider_id_foreign",
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"columnNames": ["provider_id"],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_shipping_option_id_foreign": {
|
||||
"constraintName": "fulfillment_shipping_option_id_foreign",
|
||||
"columnNames": [
|
||||
"shipping_option_id"
|
||||
],
|
||||
"columnNames": ["shipping_option_id"],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.shipping_option",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_delivery_address_id_foreign": {
|
||||
"constraintName": "fulfillment_delivery_address_id_foreign",
|
||||
"columnNames": [
|
||||
"delivery_address_id"
|
||||
],
|
||||
"columnNames": ["delivery_address_id"],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment_address",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
@@ -1639,9 +1554,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_label_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -1652,13 +1565,9 @@
|
||||
"foreignKeys": {
|
||||
"fulfillment_label_fulfillment_id_foreign": {
|
||||
"constraintName": "fulfillment_label_fulfillment_id_foreign",
|
||||
"columnNames": [
|
||||
"fulfillment_id"
|
||||
],
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"localTableName": "public.fulfillment_label",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
@@ -1823,9 +1732,7 @@
|
||||
},
|
||||
{
|
||||
"keyName": "fulfillment_item_pkey",
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
@@ -1836,13 +1743,9 @@
|
||||
"foreignKeys": {
|
||||
"fulfillment_item_fulfillment_id_foreign": {
|
||||
"constraintName": "fulfillment_item_fulfillment_id_foreign",
|
||||
"columnNames": [
|
||||
"fulfillment_id"
|
||||
],
|
||||
"columnNames": ["fulfillment_id"],
|
||||
"localTableName": "public.fulfillment_item",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.fulfillment",
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250120115002 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'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;'
|
||||
)
|
||||
this.addSql(
|
||||
'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;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_shipping_option_provider_id" ON "shipping_option" (provider_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'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;'
|
||||
)
|
||||
this.addSql(
|
||||
'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 set null;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" drop constraint if exists "shipping_option_provider_id_foreign";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "shipping_option" drop constraint if exists "shipping_option_shipping_option_type_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" drop constraint if exists "fulfillment_provider_id_foreign";'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table if exists "fulfillment" drop constraint if exists "fulfillment_delivery_address_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_shipping_option_provider_id";')
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"namespaces": ["public"],
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
@@ -87,9 +89,19 @@
|
||||
"name": "notification_provider",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_notification_provider_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_provider_deleted_at\" ON \"notification_provider\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "notification_provider_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -216,7 +228,11 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "'pending'",
|
||||
"enumItems": ["pending", "success", "failure"],
|
||||
"enumItems": [
|
||||
"pending",
|
||||
"success",
|
||||
"failure"
|
||||
],
|
||||
"mappedType": "enum"
|
||||
},
|
||||
"provider_id": {
|
||||
@@ -288,9 +304,19 @@
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_provider_id\" ON \"notification\" (provider_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_notification_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_notification_deleted_at\" ON \"notification\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "notification_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -300,9 +326,13 @@
|
||||
"foreignKeys": {
|
||||
"notification_provider_id_foreign": {
|
||||
"constraintName": "notification_provider_id_foreign",
|
||||
"columnNames": ["provider_id"],
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"localTableName": "public.notification",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.notification_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250120110514 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_provider_deleted_at" ON "notification_provider" (deleted_at) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_deleted_at" ON "notification" (deleted_at) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_notification_provider_deleted_at";');
|
||||
|
||||
this.addSql('drop index if exists "IDX_notification_deleted_at";');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -784,15 +784,6 @@
|
||||
"name": "payment",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"payment_session_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "payment_payment_session_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_payment_payment_collection_id",
|
||||
"columnNames": [],
|
||||
@@ -802,12 +793,12 @@
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_payment_collection_id\" ON \"payment\" (payment_collection_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_payment_payment_session_id",
|
||||
"keyName": "IDX_payment_payment_session_id_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_payment_session_id\" ON \"payment\" (payment_session_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_payment_payment_session_id_unique\" ON \"payment\" (payment_session_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_payment_deleted_at",
|
||||
@@ -825,6 +816,14 @@
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_provider_id\" ON \"payment\" (provider_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_payment_payment_session_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_payment_payment_session_id\" ON \"payment\" (payment_session_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "payment_pkey",
|
||||
"columnNames": [
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250120110552 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "payment" drop constraint if exists "payment_payment_session_id_unique";'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_payment_payment_session_id_unique" ON "payment" (payment_session_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_payment_payment_session_id_unique";')
|
||||
this.addSql(
|
||||
'alter table if exists "payment" add constraint "payment_payment_session_id_unique" unique ("payment_session_id");'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -242,15 +242,6 @@
|
||||
"name": "promotion_campaign_budget",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"campaign_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "promotion_campaign_budget_campaign_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_campaign_budget_type",
|
||||
"columnNames": [],
|
||||
@@ -260,12 +251,12 @@
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_campaign_budget_type\" ON \"promotion_campaign_budget\" (type) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_promotion_campaign_budget_campaign_id",
|
||||
"keyName": "IDX_promotion_campaign_budget_campaign_id_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_promotion_campaign_budget_campaign_id\" ON \"promotion_campaign_budget\" (campaign_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_promotion_campaign_budget_campaign_id_unique\" ON \"promotion_campaign_budget\" (campaign_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_promotion_campaign_budget_deleted_at",
|
||||
@@ -630,15 +621,6 @@
|
||||
"name": "promotion_application_method",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"promotion_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "promotion_application_method_promotion_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_application_method_type",
|
||||
"columnNames": [],
|
||||
@@ -664,12 +646,12 @@
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_application_method_allocation\" ON \"promotion_application_method\" (allocation) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_promotion_application_method_promotion_id",
|
||||
"keyName": "IDX_promotion_application_method_promotion_id_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_promotion_application_method_promotion_id\" ON \"promotion_application_method\" (promotion_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_promotion_application_method_promotion_id_unique\" ON \"promotion_application_method\" (promotion_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_promotion_application_method_deleted_at",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250120110700 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('alter table if exists "promotion_campaign_budget" drop constraint if exists "promotion_campaign_budget_campaign_id_unique";');
|
||||
this.addSql('drop index if exists "IDX_promotion_campaign_budget_campaign_id";');
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_promotion_campaign_budget_campaign_id_unique" ON "promotion_campaign_budget" (campaign_id) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('alter table if exists "promotion_application_method" drop constraint if exists "promotion_application_method_promotion_id_unique";');
|
||||
this.addSql('drop index if exists "IDX_promotion_application_method_promotion_id";');
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_promotion_application_method_promotion_id_unique" ON "promotion_application_method" (promotion_id) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_promotion_campaign_budget_campaign_id_unique";');
|
||||
this.addSql('alter table if exists "promotion_campaign_budget" add constraint "promotion_campaign_budget_campaign_id_unique" unique ("campaign_id");');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_promotion_campaign_budget_campaign_id" ON "promotion_campaign_budget" (campaign_id) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('drop index if exists "IDX_promotion_application_method_promotion_id_unique";');
|
||||
this.addSql('alter table if exists "promotion_application_method" add constraint "promotion_application_method_promotion_id_unique" unique ("promotion_id");');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_promotion_application_method_promotion_id" ON "promotion_application_method" (promotion_id) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"namespaces": ["public"],
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
@@ -86,9 +88,19 @@
|
||||
"name": "region",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_region_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_region_deleted_at\" ON \"region\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "region_pkey",
|
||||
"columnNames": ["id"],
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -198,17 +210,35 @@
|
||||
"name": "region_country",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_region_country_region_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_region_country_region_id\" ON \"region_country\" (region_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_region_country_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_region_country_deleted_at\" ON \"region_country\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_region_country_region_id_iso_2_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_region_country_region_id_iso_2_unique\" ON \"region_country\" (region_id, iso_2)"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_region_country_region_id_iso_2_unique\" ON \"region_country\" (region_id, iso_2) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "region_country_pkey",
|
||||
"columnNames": ["iso_2"],
|
||||
"columnNames": [
|
||||
"iso_2"
|
||||
],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
@@ -218,9 +248,13 @@
|
||||
"foreignKeys": {
|
||||
"region_country_region_id_foreign": {
|
||||
"constraintName": "region_country_region_id_foreign",
|
||||
"columnNames": ["region_id"],
|
||||
"columnNames": [
|
||||
"region_id"
|
||||
],
|
||||
"localTableName": "public.region_country",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.region",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250120110744 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_region_deleted_at" ON "region" (deleted_at) WHERE deleted_at IS NULL;');
|
||||
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_region_country_region_id" ON "region_country" (region_id) WHERE deleted_at IS NULL;');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_region_country_deleted_at" ON "region_country" (deleted_at) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_region_deleted_at";');
|
||||
|
||||
this.addSql('drop index if exists "IDX_region_country_region_id";');
|
||||
this.addSql('drop index if exists "IDX_region_country_deleted_at";');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -228,21 +228,12 @@
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"address_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "stock_location_address_id_unique",
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_stock_location_address_id",
|
||||
"keyName": "IDX_stock_location_address_id_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_stock_location_address_id\" ON \"stock_location\" (address_id) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_stock_location_address_id_unique\" ON \"stock_location\" (address_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_stock_location_deleted_at",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250120110820 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('alter table if exists "stock_location" drop constraint if exists "stock_location_address_id_unique";');
|
||||
this.addSql('drop index if exists "IDX_stock_location_address_id";');
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_stock_location_address_id_unique" ON "stock_location" (address_id) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_stock_location_address_id_unique";');
|
||||
this.addSql('alter table if exists "stock_location" add constraint "stock_location_address_id_unique" unique ("address_id");');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_stock_location_address_id" ON "stock_location" (address_id) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,11 @@ export const WorkflowExecution = model
|
||||
on: ["transaction_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["workflow_id", "transaction_id"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["state"],
|
||||
where: "deleted_at IS NULL",
|
||||
|
||||
@@ -137,6 +137,14 @@
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_workflow_execution_transaction_id\" ON \"workflow_execution\" (transaction_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_workflow_execution_workflow_id_transaction_id_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_workflow_execution_workflow_id_transaction_id_unique\" ON \"workflow_execution\" (workflow_id, transaction_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_workflow_execution_state",
|
||||
"columnNames": [],
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250120111059 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_workflow_execution_workflow_id_transaction_id_unique" ON "workflow_execution" (workflow_id, transaction_id) WHERE deleted_at IS NULL;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_workflow_execution_workflow_id_transaction_id_unique";');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,11 @@ export const WorkflowExecution = model
|
||||
on: ["transaction_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["workflow_id", "transaction_id"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
},
|
||||
{
|
||||
on: ["state"],
|
||||
where: "deleted_at IS NULL",
|
||||
|
||||
Reference in New Issue
Block a user