Skip to content

Pricing Schema

The pricing schema contains 7 models that implement a flexible, rule-based pricing engine. It supports static pricing, dynamic pricing with contextual rules, hierarchical fare structures, costs, and multi-tax configuration.

Source: packages/core/src/models/schemas/pricing/

Models Overview

ModelTable NameDescription
Farepricing.FarePrice point with amount, validity period, and quantity constraints
FareSetpricing.FareSetContainer linking a ProductVariant to its pricing configuration
FareRulepricing.FareRuleConditional rule that must be satisfied for a Fare to apply
Costpricing.CostProduct variant cost tracking with time-based effective periods
Taxpricing.TaxTax rate entries within a tax set
TaxSetpricing.TaxSetTax configuration container using polymorphic ownership
TaxTypepricing.TaxTypeTax type definitions (VAT, Excise, etc.)

Fare

A pricing tier with optional validity period, quantity constraints, and rule-based conditions. Supports parent-child hierarchies for override/promotional pricing.

ColumnTypeConstraintsDescription
namejsonb (i18n)Internationalized name
descriptionjsonb (i18n)Internationalized description
statustextNOT NULL, DEFAULT ACTIVATEDFare status
typetextFare type (SALE, OVERRIDE)
effective_fromisoTimestampValidity start date
effective_toisoTimestampValidity end date
min_quantitydecimal(15,4)Minimum quantity for this fare
max_quantitydecimal(15,4)Maximum quantity for this fare
amountdecimal(15,4)Price amount
rules_countintegerCached count of attached rules
children_countintegerCached count of child fares
fare_set_idtextNOT NULLFK to FareSet
parent_idtextFK to parent Fare (self-reference)
+ common columnsid, createdAt, modifiedAt, deletedAt, metadata

Statuses: ACTIVATED, DEACTIVATED, ARCHIVED

Types:

  • SALE -- Standard sale price
  • OVERRIDE -- Override/promotional price

FareSet

Container linking a ProductVariant to its pricing configuration. One-to-one relationship with ProductVariant.

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT ACTIVATEDFareSet status
product_variant_idtextNOT NULL, UNIQUEOne FareSet per ProductVariant
+ common columns

Statuses: ACTIVATED, DEACTIVATED, ARCHIVED

Relations: One FareSet has many Fares.

FareRule

Conditional rule attached to a Fare. All rules on a Fare must pass for the Fare to apply. Rules are evaluated in priority order.

ColumnTypeConstraintsDescription
codetextNOT NULLRule identifier (e.g., quantity, saleChannelId)
priorityintegerNOT NULLEvaluation order (lower = first)
operatortextNOT NULLComparison operator
fare_idtextNOT NULLFK to Fare
+ data-type columnsdataType, tValue, nValue, boValue, bValue, jValue
+ common columns

Operators (from FareRuleOperators):

OperatorAliasesDescription
eqEqual
neneqNot equal
gtGreater than
gteGreater than or equal
ltLess than
lteLess than or equal
ininqIn array
ninNot in array

The generateDataTypeColumnDefs() helper provides typed value storage:

  • tValue (text) -- for string comparisons
  • nValue (double precision) -- for numeric comparisons
  • boValue (boolean) -- for boolean checks
  • bValue (bytea) -- for binary data
  • jValue (jsonb) -- for complex rules

Cost

Product variant cost tracking with time-based effective periods.

ColumnTypeConstraintsDescription
amountdecimal(15,4)NOT NULLCost amount
notetextCost note
effective_fromisoTimestampNOT NULLPeriod start (required)
effective_toisoTimestampPeriod end (null = indefinite)
product_variant_idtextNOT NULLFK to ProductVariant
created_bytextCreator user ID
modified_bytextLast modifier user ID
+ common columns

Tax

Individual tax rate entries within a tax set.

ColumnTypeConstraintsDescription
namejsonb (i18n)NOT NULLInternationalized name
amountdecimal(15,4)Fixed tax amount
percentagedecimal(15,4)Tax percentage rate
effective_fromisoTimestampNOT NULLPeriod start
effective_toisoTimestampPeriod end
priorityintegerDEFAULT 0Evaluation order (highest first when multiple taxes apply)
statustextNOT NULL, DEFAULT ACTIVATEDTax status
tax_set_idtextNOT NULLFK to TaxSet
tax_type_idtextNOT NULLFK to TaxType
+ common columns

Statuses: ACTIVATED, DEACTIVATED, ARCHIVED

TaxSet

Tax configuration container using polymorphic ownership (can be linked to any entity).

ColumnTypeConstraintsDescription
principal_idtextPolymorphic owner ID
principal_typetextPolymorphic owner type
namejsonb (i18n)Internationalized name
statustextNOT NULL, DEFAULT ACTIVATEDTaxSet status
+ common columns

Unique constraint: (principalId, principalType, status, deletedAt)

Statuses: ACTIVATED, DEACTIVATED, ARCHIVED

TaxType

Tax type definitions shared across merchants.

ColumnTypeConstraintsDescription
typetextNOT NULLTax type code
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
statustextNOT NULL, DEFAULT ACTIVATEDTaxType status
merchant_idtextFK to Merchant (null for global types)
+ common columns

Unique constraint: (type, merchantId)

Fixed Tax Types (from FixedTaxTypes):

ConstantValueDescription
VAT000_VATValue-Added Tax
EXCISE100_EXCISE5Excise tax
ENVIRONMENTAL200_ENVIRONMENTALEnvironmental tax
LUXURY300_LUXURYLuxury tax

Entity Relationships

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.