Skip to main content

Database

Database tables and auto-migration system

This section

Database

All tables are created automatically on first start. The script includes an auto-migration system that adds new columns when upgrading.

Tables

code9_shop_settings

Main shop configuration table.

ColumnTypeDefaultDescription
shopIdINT (PK, AI)Unique shop identifier
creatorLicenseVARCHAR(255)License of the shop creator
shopNameVARCHAR(255)Internal shop name
shopLabelVARCHAR(255)Display label
jobVARCHAR(50)'all'Required job ('all' for none)
blipTEXTBlip settings (JSON)
pedTEXTPed settings (JSON)
interactCoordsTEXTLegacy interaction coordinates
themeTEXTTheme settings (JSON)
interactionDistanceFLOATNULLShop-level interaction distance
webhookTEXTNULLWebhook settings (JSON)
createdAtTIMESTAMPCURRENTCreation timestamp

code9_shop_stocks

Products/items for each shop.

ColumnTypeDefaultDescription
idINT (PK, AI)Unique product identifier
shopIdINTParent shop ID
itemNameVARCHAR(255)Inventory item code
nameVARCHAR(255)Display name
imageTEXTImage URL
priceDECIMAL(10,2)Item price
categoryVARCHAR(100)Category assignment
descriptionTEXTItem description
isStockTINYINT(1)0Stock tracking enabled
stockINT0Current stock amount
jobGradeINT0Minimum job grade required
itemJobVARCHAR(50)''Required job for this item
createdAtTIMESTAMPCURRENTCreation timestamp

code9_shop_category

Categories for each shop.

ColumnTypeDefaultDescription
idVARCHAR(100)Category ID (composite PK)
shopIdINTParent shop ID (composite PK)
nameVARCHAR(255)Category name
imageTEXTCategory image URL
createdAtTIMESTAMPCURRENTCreation timestamp

code9_shop_locations

Multi-location support table.

ColumnTypeDefaultDescription
locationIdINT (PK, AI)Unique location identifier
shopIdINT (indexed)Parent shop ID
locationNameVARCHAR(255)Location display name
interactCoordsTEXTInteraction coordinates (JSON)
blipTEXTBlip settings (JSON)
pedTEXTPed settings (JSON)
enabledTINYINT(1)1Location enabled state
interactionDistanceFLOATNULLPer-location interaction distance
createdAtTIMESTAMPCURRENTCreation timestamp

Auto-Migration

The script automatically handles schema changes:

  • New columns are added to existing tables without data loss
  • Legacy single-location shops are migrated to the code9_shop_locations table
  • No manual SQL is needed when upgrading

Cascading Delete

When a shop is deleted, all related data is removed in order:

  1. code9_shop_stocks (products)
  2. code9_shop_category (categories)
  3. code9_shop_locations (locations)
  4. code9_shop_settings (shop itself)