> For the complete documentation index, see [llms.txt](https://docs.dsyncstudios.store/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dsyncstudios.store/products/dsync-banking/reference/database-schema.md).

# Database Schema

## Database Schema

Dsync-Banking manages **13 tables**, all created and migrated automatically from `schema.sql` on resource start (see the [Installation guide](/products/dsync-banking/getting-started/installation-and-requirements.md)). You never need to run SQL by hand under normal operation.

All monetary columns are `BIGINT UNSIGNED` storing **cents** — see [Why money is stored in cents](/products/dsync-banking/configuration-reference.md#why-money-is-stored-in-cents).

| #  | Table                       | Purpose                                                                         |
| -- | --------------------------- | ------------------------------------------------------------------------------- |
| 1  | `bank_accounts`             | Core account table — personal, shared, savings, and society-linked account rows |
| 2  | `bank_account_members`      | Junction table for shared-account membership, roles, and per-member permissions |
| 3  | `bank_transactions`         | Append-only audit ledger for every personal/shared account movement             |
| 4  | `bank_cards`                | Virtual and physical bank cards — PIN hash, freeze state, daily limit/spend     |
| 5  | `bank_loans`                | Active and historical loans — amortization, missed payments, bounce charges     |
| 6  | `bank_savings`              | Interest-bearing savings sub-accounts                                           |
| 7  | `bank_credit_scores`        | FICO-style 300–850 credit score per citizen                                     |
| 8  | `bank_bills`                | Bills, fines, invoices, and their payment status                                |
| 9  | `bank_societies`            | Job/gang treasury accounts                                                      |
| 10 | `bank_society_transactions` | Append-only audit ledger for society money movement                             |
| 11 | `bank_beneficiaries`        | Saved transfer recipients ("address book")                                      |
| 12 | `bank_money_requests`       | Peer-to-peer money requests ("Player A asks Player B for $X")                   |
| 13 | `bank_scheduled_transfers`  | Recurring auto-payments (rent, payroll)                                         |

### Key design notes

* **Personal balances are framework-authoritative.** A personal account's true balance lives in the framework (`players.money.bank`), not in `bank_accounts.balance`. That column is a **mirror**, re-synced from the framework on every dashboard open and used only to compute `balance_after` in the ledger. Shared, society, and savings accounts *are* database-authoritative — their balance column is the source of truth.
* **Transactions are append-only.** `bank_transactions` and `bank_society_transactions` are never updated or deleted from in normal operation; they're an audit trail. A write-behind buffer batches inserts every few minutes for efficiency, with an in-memory read-cache so recent transactions are still visible instantly.
* **Boolean-flag safety.** Every `TINYINT(1)` flag (`is_frozen`, `can_deposit`, etc.) is normalized through a single helper before being compared or sent to the UI, because MySQL drivers can return `TINYINT(1)` as either a Lua number or a Lua boolean depending on version — comparing directly against `1` is a latent bug the codebase deliberately guards against everywhere.
* **Idempotent migrations.** Schema changes ship as `ADD COLUMN IF NOT EXISTS` / guarded `ALTER TABLE` statements appended to `schema.sql`, executed statement-by-statement with each one wrapped so a single failure doesn't block the rest from applying.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dsyncstudios.store/products/dsync-banking/reference/database-schema.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
