fix(promotion): scope uniqueness index to non deleted promotions (#11624)

what:

- scopes uniqueness index to only non deleted records
- explicit sorting of buy get promotions
  - This error popped up as we removed the uniqueness constraint which seems to have kept a specific order.  
  
  
RESOLVES https://github.com/medusajs/medusa/issues/11606
This commit is contained in:
Riqwan Thamir
2025-02-26 14:25:43 +00:00
committed by GitHub
parent d2d6a29a4a
commit a515e6e0c9
5 changed files with 164 additions and 54 deletions
@@ -6,11 +6,7 @@ import PromotionRule from "./promotion-rule"
const Promotion = model
.define("Promotion", {
id: model.id({ prefix: "promo" }).primaryKey(),
code: model
.text()
.searchable()
.unique("IDX_promotion_code_unique")
.index("IDX_promotion_code"),
code: model.text().searchable(),
is_automatic: model.boolean().default(false),
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
status: model
@@ -35,5 +31,13 @@ const Promotion = model
.cascades({
delete: ["application_method"],
})
.indexes([
{
name: "IDX_unique_promotion_code",
on: ["code"],
where: "deleted_at IS NULL",
unique: true,
},
])
export default Promotion