fix(tax): Add indexes to enforce unique constraint on tax region (#8067)

This commit is contained in:
Oli Juhl authored and GitHub committed 2024-07-10 20:09:19 +02:00
1 parent 74c19308a0
commit 256912f392
4 files changed
+226 -3

No files matched your search

@@ -168,7 +168,15 @@
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_tax_region_unique_country_province\" ON \"tax_region\" (country_code, province_code)"
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_tax_region_unique_country_province\" ON \"tax_region\" (country_code, province_code) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_tax_region_unique_country_nullable_province",
"columnNames": [],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_tax_region_unique_country_nullable_province\" ON \"tax_region\" (country_code) WHERE province_code IS NULL AND deleted_at IS NULL"
},
{
"keyName": "tax_region_pkey",
@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20240710135844 extends Migration {
async up(): Promise<void> {
this.addSql('drop index if exists "IDX_tax_region_unique_country_province";');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_tax_region_unique_country_province" ON "tax_region" (country_code, province_code) WHERE deleted_at IS NULL;');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_tax_region_unique_country_nullable_province" ON "tax_region" (country_code) WHERE province_code IS NULL AND deleted_at IS NULL;');
}
async down(): Promise<void> {
this.addSql('drop index if exists "IDX_tax_region_unique_country_province";');
this.addSql('drop index if exists "IDX_tax_region_unique_country_nullable_province";');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_tax_region_unique_country_province" ON "tax_region" (country_code, province_code);');
}
}