Skip to content

Public Schema

The public schema contains 30 models covering the core business domain. Models are defined using pgTable() from Drizzle ORM and use the shared generateCommonColumnDefs() for id, createdAt, modifiedAt, deletedAt, and metadata columns.

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

User Management

The following entity relationship diagram shows the connections between user and authorization models:

User

Core user entity representing all system users.

ColumnTypeConstraintsDescription
idtextPKSnowflake ID
realmtextDEFAULT ''User realm/tenant
statustextNOT NULLUser status (from CommonStatuses)
typetextNOT NULLUser type (SYSTEM, LINKED)
activated_attimestamptzAccount activation time
last_login_attimestamptzLast login timestamp
parent_idtextParent user reference
+ common columnscreatedAt, modifiedAt, deletedAt, metadata

Uses extraUserColumns({ idType: 'string' }) from IGNIS.

UserProfile

Extended user information (one-to-one with User).

ColumnTypeConstraintsDescription
emailstext[]DEFAULT '{}'Array of email addresses
phonestext[]DEFAULT '{}'Array of phone numbers
first_nametextGiven name
last_nametextFamily name
birthdayisoTimestampBirth date (ISO 8601 string)
localetextDEFAULT 'en-US'Locale preference
user_idtextNOT NULLFK to User
+ common columns

UserIdentifier

Multiple identification methods for users.

ColumnTypeConstraintsDescription
schemetextNOT NULLIdentifier type (USERNAME, EMAIL, PHONE_NUMBER, USER_NUMBER, NX_AUTH)
identifiertextNOT NULLIdentifier value
verifiedbooleanNOT NULL, DEFAULT falseVerification status
user_idtextNOT NULLFK to User
+ common columns

Unique constraint: (scheme, identifier)

UserCredential

Authentication credentials (passwords, OAuth tokens).

ColumnTypeConstraintsDescription
schemetextNOT NULLCredential type (BASIC, TWO_FA, OAUTH, OAUTH2)
credentialtextNOT NULLHashed credential value
user_idtextNOT NULLFK to User
+ common columns

UserConfiguration

Per-user configuration settings using the data-type column pattern.

ColumnTypeConstraintsDescription
nametextConfiguration name
codetextNOT NULLConfiguration code (e.g., PREFERENCES)
descriptiontextDescription
grouptextNOT NULLConfiguration group
user_idtextNOT NULLFK to User
+ data-type columnsdataType, tValue, nValue, boValue, bValue, jValue
+ common columns

UserMapping

Maps users to organizations and merchants using polymorphic references.

ColumnTypeConstraintsDescription
principal_idtextPolymorphic target ID (e.g., organizer or merchant ID)
principal_typetextPolymorphic target type (e.g., Organizer, Merchant)
user_idtextNOT NULLFK to User
+ common columns

UserRole

Associates users with roles using polymorphic scoping.

ColumnTypeConstraintsDescription
principal_idtextScope ID (e.g., organizer ID for scoped roles)
principal_typetextScope type
user_idtextNOT NULLFK to User
+ common columns

Authorization

Role

Role definitions for RBAC with i18n support.

ColumnTypeConstraintsDescription
identifiertextNOT NULL, UNIQUERole code (e.g., 999-super-admin)
priorityintegerNOT NULLPriority level (higher = more privileged)
statustextNOT NULLRole status
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
+ common columns

Uses extraRoleColumns() from IGNIS. Predefined roles:

RoleIdentifierPriority
Super Admin999-super-admin999
Admin998-admin998
Operator997-operator997
Organizer Owner899-organizer-owner899
Employee898-employee898

Permission

Permission definitions for access control.

ColumnTypeConstraintsDescription
codetextNOT NULL, UNIQUEPermission code
nametextNOT NULLPermission name
subjecttextNOT NULLResource subject
p_typetextNOT NULLPermission type
actiontextNOT NULLAllowed action
scopetextNOT NULLPermission scope
parent_idtextParent permission FK
+ common columns

Uses extraPermissionColumns({ idType: 'string' }) from IGNIS.

PermissionMapping

Maps permissions to roles (many-to-many join table).

ColumnTypeConstraintsDescription
+ permission mapping columnsFrom extraPermissionMappingColumns({ idType: 'string' })
+ common columns

Organization

The following entity relationship diagram shows the connections between organization and product models:

Organizer

Top-level business organization entity with legal, contact, and location details.

ColumnTypeConstraintsDescription
slugtextNOT NULL, UNIQUEURL-friendly identifier
statustextNOT NULL, DEFAULT ACTIVATEDOrganizer status
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., O_20260216_...)
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
tax_numbertextTax identification number
registration_numbertextBusiness registration number
registration_typetextRegistration type (VN_HOUSEHOLD_BUSINESS, VN_PRIVATE_ENTERPRISE, etc.)
registration_dateisoTimestampRegistration date
license_numbertextBusiness license number
vat_numbertextVAT number
contact_nametextPrimary contact name
contact_phonetextContact phone
contact_emailtextContact email
websitetextWebsite URL
locationjsonb (ILocation)Physical address and coordinates
socialjsonb (ISocial)Social media links
parent_idtextParent organizer FK
created_bytextCreator user ID
modified_bytextLast modifier user ID
+ common columns

Merchant

Store/branch entity under an organizer.

ColumnTypeConstraintsDescription
slugtextNOT NULLURL-friendly identifier (unique per organizer)
statustextNOT NULL, DEFAULT ACTIVATEDMerchant status
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., M_20260216_...)
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
currencytextNOT NULLCurrency code (e.g., VND)
typetextNOT NULLMerchant type (DEFAULT, TICKET, FNB, THEATER)
date_fromisoTimestampOperating start date
date_toisoTimestampOperating end date
locationjsonb (ILocation)Physical address and coordinates
parent_idtextParent merchant FK
organizer_idtextNOT NULLFK to Organizer
+ common columns

Unique constraint: (slug, organizer_id)

MerchantIdentifier

External identifiers for merchants (e.g., payment provider merchant IDs).

ColumnTypeConstraintsDescription
schemetextNOT NULLIdentifier scheme (SYSTEM, SLUG, VNPAY_QR_MMS, VNPAY_PHONE_POS, VNPAY_SMART_POS)
identifiertextNOT NULLIdentifier value
merchant_idtextNOT NULLFK to Merchant
+ common columns

Unique constraint: (scheme, identifier)

Product

Product

Main product entity.

ColumnTypeConstraintsDescription
slugtextNOT NULLURL-friendly identifier (unique per merchant)
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., P_20260216_...)
statustextNOT NULL, DEFAULT ACTIVATEDProduct status
merchant_idtextNOT NULLFK to Merchant
category_idtextFK to Category
parent_idtextParent product FK
+ common columns

Unique constraint: (slug, merchant_id)

ProductInfo

Extended product details using polymorphic reference pattern.

ColumnTypeConstraintsDescription
principal_idtextPolymorphic owner ID (Product or ProductVariant ID)
principal_typetextPolymorphic owner type
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
+ common columns

ProductIdentifier

Multiple identification schemes for products (SKU, barcode, QR code).

ColumnTypeConstraintsDescription
principal_idtextPolymorphic owner ID
principal_typetextPolymorphic owner type
schemetextNOT NULLScheme (SYSTEM, SLUG, SKU, BARCODE, QRCODE)
identifiertextNOT NULLIdentifier value
+ common columns

Unique constraint: (scheme, identifier)

ProductVariant

Product variations with costing and allocation support.

ColumnTypeConstraintsDescription
slugtextNOT NULLURL-friendly identifier
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., PV_20260216_...)
statustextNOT NULL, DEFAULT NEWVariant status (NEW, ACTIVATED, DEACTIVATED, ARCHIVED)
date_fromisoTimestampAvailability start date
date_toisoTimestampAvailability end date
costdecimal(15,4)Unit cost
costing_methodstextDEFAULT TIME_BASEDCosting method (TIME_BASED, FIFO, LIFO, AVERAGE)
product_idtextNOT NULLFK to Product
allocation_plan_idtextFK to AllocationPlan
allocation_layout_idtextFK to AllocationLayout
allocation_zone_idtextFK to AllocationZone
allocation_unit_idtextFK to AllocationUnit
+ common columns

ProductVariantMapping

Maps product variants to variant attributes using polymorphic references.

ColumnTypeConstraintsDescription
principal_idtextPolymorphic ID
principal_typetextPolymorphic type
product_variant_idtextNOT NULLFK to ProductVariant
+ common columns

Variant

Variant attribute definitions (e.g., Size, Color).

ColumnTypeConstraintsDescription
principal_typetextOwner type
principal_idtextOwner ID
codetextNOT NULLVariant code
+ data-type columnsdataType, tValue, nValue, boValue, bValue, jValue
+ common columns

Category

Product categorization with i18n support.

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT UNKNOWNCategory status
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
is_addonbooleanNOT NULL, DEFAULT falseWhether this is an addon category
merchant_idtextNOT NULLFK to Merchant
+ common columns

Commerce

The following entity relationship diagram shows the connections between commerce and system models:

SaleChannel

Sales channels for distributing products.

ColumnTypeConstraintsDescription
slugtextNOT NULLURL-friendly identifier (unique per merchant)
statustextNOT NULL, DEFAULT ACTIVATEDChannel status
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., S_20260216_...)
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
merchant_idtextNOT NULLFK to Merchant
parent_idtextParent channel FK
+ common columns

Unique constraint: (slug, merchant_id)

SaleChannelProduct

Join table linking products to sale channels.

ColumnTypeConstraintsDescription
product_idtextNOT NULLFK to Product
sale_channel_idtextNOT NULLFK to SaleChannel
+ common columns

Quota

Quantity limits for campaigns.

ColumnTypeConstraintsDescription
quantityintegerNOT NULLAvailable quantity
statustextNOT NULL, DEFAULT UNKNOWNQuota status
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
campaign_idtextNOT NULLFK to Campaign
+ common columns

Campaign

Promotional campaigns.

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT UNKNOWNCampaign status
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
date_fromtimestamptzCampaign start date
date_totimestamptzCampaign end date
merchant_idtextNOT NULLFK to Merchant
+ common columns

System

Configuration

System and integration configuration with encrypted credential support.

ColumnTypeConstraintsDescription
codetextNOT NULLConfiguration code
nametextConfiguration name
descriptiontextDescription
grouptextNOT NULLGroup (SYSTEM, TABLE, INTEGRATION)
statustextDEFAULT ACTIVATEDConfiguration status
environmenttextEnvironment context
credentialtextEncrypted credential (hidden, never returned)
principalIdtextOwner entity ID
principalTypetextOwner entity type
created_bytextCreator user ID
modified_bytextLast modifier user ID
+ data-type columnsdataType, tValue, nValue, boValue, bValue, jValue
+ common columns

Unique constraint: (group, code, principalId, principalType, environment, deletedAt)

Indexes: (group, code, environment), (group, principalType), GIN on metadata

Settings

Key-value settings using polymorphic ownership and data-type storage.

ColumnTypeConstraintsDescription
principal_idtextOwner entity ID
principal_typetextOwner entity type
created_bytextCreator
modified_bytextLast modifier
+ data-type columnsdataType, tValue, nValue, boValue, bValue, jValue
+ common columns

Unique constraint: (principalId, principalType, deletedAt)

Device

POS devices and terminals with hardware/software info.

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT NEWDevice status (NEW, ACTIVATED, DEACTIVATED, SUSPENDED, ARCHIVED)
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
identifiertextNOT NULL, UNIQUEAuto-generated (e.g., D_20260216_...)
codetextUNIQUEShort code
typetextNOT NULLDevice type (POS_TERMINAL, MOBILE_POS, TABLET, BARCODE_SCANNER, etc.)
locationjsonb (ILocation)Physical location
organizer_idtextNOT NULLFK to Organizer
merchant_idtextFK to Merchant
hardware_infojsonbIDeviceHardwareInfo (manufacturer, model, serialNumber, etc.)
software_infojsonbIDeviceSoftwareInfo (os, osVersion, appVersion, etc.)
last_activity_atisoTimestampLast activity timestamp
activated_atisoTimestampActivation timestamp
deactivated_atisoTimestampDeactivation timestamp
pintextDevice PIN
purchase_dateisoTimestampPurchase date
warranty_expires_atisoTimestampWarranty expiration
last_maintenance_atisoTimestampLast maintenance
next_maintenance_atisoTimestampNext scheduled maintenance
maintenance_notestextMaintenance notes
vendortextDevice vendor
+ common columns

Media/file metadata for assets stored in Minio or local disk.

ColumnTypeConstraintsDescription
idtextPKSnowflake ID
bucket_nametextNOT NULL, indexedStorage bucket
object_nametextNOT NULL, indexedObject name in storage
linktextNOT NULLAccess URL (presigned)
mimetypetextNOT NULLMIME type
sizeintegerNOT NULLFile size in bytes
etagtextEntity tag
metadatajsonbAdditional metadata
storage_typetextNOT NULL, indexedStorage type (minio, disk)
is_syncedbooleanNOT NULL, DEFAULT false, indexedSync status
principal_typetextOwner entity type
principal_idtextOwner entity ID
created_attimestamptzCreation time
modified_attimestamptzLast modification

Note: MetaLink uses generateIdColumnDefs + generateTzColumnDefs directly (no deletedAt).

Migration

Tracks seed data migration execution.

ColumnTypeConstraintsDescription
idtext/serialPKAuto-increment or generated ID
nametextNOT NULLMigration name
statustextNOT NULLMigration status (from MigrationStatuses)
created_attimestamptzExecution time
modified_attimestamptzLast update

Note: Uses generateIdColumnDefs() (without string option) and generateTzColumnDefs().

EmailVerification

Email verification codes and tokens with rate limiting.

ColumnTypeConstraintsDescription
verification_codevarcharNOT NULL, indexed6-digit verification code
code_generated_attimestamptzNOT NULLCode generation time
code_expires_attimestamptzNOT NULL, indexedCode expiration (10 min)
code_attemptsintegerNOT NULL, DEFAULT 0Failed attempt count (max 3)
verification_tokenvarcharNOT NULL, indexed32-byte verification token
token_generated_attimestamptzNOT NULLToken generation time
token_expires_attimestamptzNOT NULL, indexedToken expiration (24 hours)
last_code_sent_attimestamptzNOT NULLLast code send time
resend_countintegerNOT NULL, DEFAULT 0Resend count (max 5/day)
daily_resend_reset_attimestamptzNOT NULLDaily reset timestamp
locked_untiltimestamptzLockout expiration (15 min)
is_verifiedbooleanNOT NULL, DEFAULT falseVerification status
verified_attimestamptzVerification timestamp
verification_methodvarcharMethod used (code or token)
verification_ipvarcharIP address used
user_identifier_idtextNOT NULL, indexedFK to UserIdentifier
+ common columns

Auto-Generated Identifiers

Most entities use auto-generated identifiers with the format {PREFIX}_{YYYYMMDD}_{SNOWFLAKE_ID}:

EntityPrefixExample
OrganizerO_O_20260216_1234567890
MerchantM_M_20260216_1234567890
ProductP_P_20260216_1234567890
ProductVariantPV_PV_20260216_1234567890
SaleChannelS_S_20260216_1234567890
DeviceD_D_20260216_1234567890

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