Skip to content

Commit

Permalink
chore: update unique index
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan committed Nov 28, 2024
1 parent 9d8e525 commit 3187982
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,12 @@
"unique": false
},
{
"keyName": "IDX_price_rule_price_id_attribute_unique",
"keyName": "IDX_price_rule_price_id_attribute_operator_unique",
"columnNames": ["price_id"],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_id_attribute_unique\" ON \"price_rule\" (price_id, attribute) WHERE deleted_at IS NULL"
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_price_rule_price_id_attribute_operator_unique\" ON \"price_rule\" (price_id, attribute, operator) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_price_rule_deleted_at",
Expand Down
21 changes: 21 additions & 0 deletions packages/modules/pricing/src/migrations/Migration20241127223829.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Migration } from "@mikro-orm/migrations"

export class Migration20241127223829 extends Migration {
async up(): Promise<void> {
this.addSql(
'drop index if exists "IDX_price_rule_price_id_attribute_unique";'
)
this.addSql(
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_attribute_operator_unique" ON "price_rule" (price_id, attribute, operator) WHERE deleted_at IS NULL;'
)
}

async down(): Promise<void> {
this.addSql(
'drop index if exists "IDX_price_rule_price_id_attribute_operator_unique";'
)
this.addSql(
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_attribute_unique" ON "price_rule" (price_id, attribute) WHERE deleted_at IS NULL;'
)
}
}
2 changes: 1 addition & 1 deletion packages/modules/pricing/src/models/price-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({

const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
tableName: tableName,
columns: ["price_id", "attribute"],
columns: ["price_id", "attribute", "operator"],
where: "deleted_at IS NULL",
unique: true,
})
Expand Down

0 comments on commit 3187982

Please sign in to comment.