Database Setup
Last updated on
Automatic (recommended)
server/migrator.lua runs on every resource start and brings the schema up to date on its own:
- Fresh install (no
dnd_eco_*tables yet) → runssql/install.sqland marks every migration as already applied. - Existing schema → resumes from the last applied migration, tracked in
dnd_eco_schema_versions. - Legacy
de_*prefix (pre-rename) → walks migrations forward from the rename point. - Hand-migrated schema (tables look current but no version rows exist yet) → creates the version table, then checks each migration's effect against the live schema and marks it applied without re-running it.
Just start the resource — nothing to run manually. Migration failure aborts boot on purpose (booting with a half-migrated schema is worse than not booting).
Manual
If you'd rather import it yourself: run sql/install.sql once against your database. It creates every table this resource needs:
| Table | Purpose |
|---|---|
dnd_eco_items | Master commodity list (base price, floor/ceiling/sensitivity/decay) |
dnd_eco_agencies | Agency config mirror (label, job, collection, commission, Buy price adjustment, webhook) |
dnd_eco_agency_stock | Per-agency-item runtime state (current price, target stock, price holds) |
dnd_eco_transactions | Sell + Buy history (direction column), buyer/seller/handler identifiers and names, order_id (groups a cart's line items into one Dashboard entry) and payment_method (cash/bank) |
dnd_eco_player_cooldowns | Per-player, per-item Sell cooldown |
dnd_eco_price_snapshots | Price history for trend sparklines |
dnd_eco_schema_versions | Migration tracking |
Config vs database
Most agency/item fields are synced from config.lua on every boot (server/config_sync.lua) — label, collection, job, commission, etc. always track your config. A few fields are dashboard-editable at runtime and deliberately excluded from that sync so they survive a restart:
dnd_eco_agencies.webhook_urldnd_eco_agencies.buy_price_adjustmentdnd_eco_items.overriddeneconomic properties (base price, floor, ceiling, sensitivity, decay) — only once a government-access user has edited them from the Dashboard.
v2.0.0 schema updates
The following migrations were added in v2.0.0 to support agency budgets, transaction tax, and price spreads:
| Migration | Adds | Purpose |
|---|---|---|
0017_price_spread | agencies.spread_pct, instansi_discount, gang_markup | Per-agency price adjustment controls |
0018_agency_budget | agencies.budget_enforced, quota_limit, quota_cycle_hours, quota_spent, cycle_start_ts | Agency spending limits and cycle tracking |
0019_stock_target_overridden | agency_stock.target_overridden | Track which stock targets have been edited from the default |
0020_transaction_tax | transactions.tax_paid | Record how much tax was collected on each transaction |
These run automatically on boot. No manual SQL needed.
Dashboard-edited fields (survive restart)
The following fields are intentionally excluded from the config sync so they survive a restart and reflect staff/manager edits made from the Dashboard:
dnd_eco_agencies.webhook_urldnd_eco_agencies.buy_price_adjustment(renamed toinstansi_discount/gang_markupin v2.0.0)dnd_eco_agencies.spread_pct,instansi_discount,gang_markupdnd_eco_agencies.quota_limit,quota_cycle_hours(per-agency overrides on top of config defaults)dnd_eco_items.overriddeneconomic properties (base price, floor, ceiling, sensitivity, decay) — only once a government-access user has edited them from the Dashboard.
All other fields are re-synced from config.lua on every boot, so config changes always take effect immediately without any manual DB edits.