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
20 lines
698 B
TypeScript
20 lines
698 B
TypeScript
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");'
|
|
)
|
|
}
|
|
}
|