🍗 PCK ZRA Middleware Wiki

Database Schema

MariaDB 10.6+ database pckmiddle. Schema is versioned with Flyway; Hibernate runs in validate mode, meaning entities must match the migrated schema.

Migrations (V001–V008)

MigrationDescription
V001__Initial_Schema.sqlCore tables (api_transactions, conversion_logs, system_config), views, stored procedures, indexes
V002__Add_Store_Id_To_Logs.sqlAdd store_id to api_transactions and conversion_logs
V003__Add_Fiscal_Invoices_Table.sqlfiscal_invoices table for receipt tracking and refund lookups
V004__Alter_Fiscal_Invoices_Receipt_Types.sqlEnsure receipt_number is VARCHAR
V005__Ensure_Receipt_Number_Varchar.sqlAdditional type safety for receipt_number
V006__Add_Menu_Sync_To_Store_Registrations.sqlAdd oracle_menu_path, menu_sync_enabled, default_department to store_registrations
V007__Enlarge_Api_Transaction_Body_Columns.sqlEnlarge api_transactions body columns to LONGTEXT
V008__Add_Buyer_Address_To_Fiscal_Invoices.sqlAdd buyer_house_no, buyer_street, buyer_province to fiscal_invoices for POS check printing

Tables

api_transactions

Full request/response audit trail for every API call.

Key columnsNotes
transaction_idUUID assigned at the door; links all records for one request
store_idTagged after store resolution (V002)
source_api, target_api, endpoint, methodRoute identification
request_headers, request_body, response_headers, response_bodyFull payloads (LONGTEXT since V007)
status_code, success, error_messageOutcome
response_time_ms, created_atTiming

conversion_logs

Data transformation audit trail.

Key columnsNotes
transaction_id, store_idLinkage
conversion_type, source_format, target_formate.g. TAXINT → CHRILAN
source_data, target_dataBefore/after payloads
mapping_rules, validation_errorsRules applied; error detail on failure
conversion_success, processing_time_msOutcome and timing

fiscal_invoices

Issued invoice records — the foundation of credit-note lookups.

Key columnsNotes
audit_numberFrom the POS cashier number
receipt_numberZRA receipt number (VARCHAR)
sdc_idSmart Device Controller ID
store_id, tpin, currencyAttribution
is_refund, original_receipt_numberRefund linkage
buyer_house_no, buyer_street, buyer_provinceBuyer address (V008)

store_registrations

Key columnsNotes
seller_namePrimary identifier; unique; must match POS SellerName exactly
tpinStore TPIN
chrilan_api_keyPer-store key; no default exists anywhere
activeSoft-delete flag
oracle_menu_path, menu_sync_enabled, default_departmentMenu sync configuration (V006)
notification_phone, notification_group_id, notifications_enabledWhatsApp alert targets

users

Key columnsNotes
emailLogin username
passwordBCrypt hash
phone_numberWhatsApp OTP destination
otp_code, otp_expiry, otp_verifiedOTP state (5-minute expiry)

system_config

Generic key-value configuration store (config_key, config_value, description).

Views

ViewPurpose
transaction_statisticsAggregated transaction success/failure counts
conversion_statisticsAggregated conversion success/failure counts

Stored procedures

ProcedurePurpose
GetTransactionStatisticsTransaction counts by date range
GetFailedTransactionsFailed transactions by date range
CleanupOldTransactionsPurge transactions older than N days — manual use only; retention is infinite by default

Indexing & performance