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:
@@ -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");'
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user