Raw
1 import { model, PricingRuleOperator } from "@medusajs/framework/utils"
2 import Price from "./price"
3
4 const PriceRule = model
5 .define("PriceRule", {
6 id: model.id({ prefix: "prule" }).primaryKey(),
7 attribute: model.text(),
8 value: model.text(),
9 operator: model.enum(PricingRuleOperator).default(PricingRuleOperator.EQ),
10 priority: model.number().default(0),
11 price: model.belongsTo(() => Price, {
12 mappedBy: "price_rules",
13 }),
14 })
15 .indexes([
16 {
17 on: ["price_id", "attribute", "operator"],
18 where: "deleted_at IS NULL",
19 unique: true,
20 },
21 {
22 on: ["attribute"],
23 where: "deleted_at IS NULL",
24 },
25 {
26 on: ["attribute", "value"],
27 where: "deleted_at IS NULL",
28 },
29 {
30 on: ["operator", "value"],
31 where: "deleted_at IS NULL",
32 },
33 {
34 on: ["attribute", "value", "price_id"],
35 where: "deleted_at IS NULL",
36 },
37 ])
38
39 export default PriceRule