> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/vip-shop/guides/database.md).

# Database Reference

All tables are created automatically on resource start (`CREATE TABLE IF NOT EXISTS`, InnoDB, utf8mb4). You never import SQL, and restarts never touch existing data.

## `vipshop_balances`

Coin wallets.

| Column       | Type                      | Notes                                                                                                                                           |
| ------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `owner`      | varchar(120), primary key | The wallet key. See [Server Configuration](/script-documentation/vip-shop/getting-started/server-configuration.md#balance-ownership-explained). |
| `balance`    | int unsigned              | Current coins                                                                                                                                   |
| `updated_at` | timestamp                 | Automatic                                                                                                                                       |

Deductions use a conditional update (`... SET balance = balance - ? WHERE owner = ? AND balance >= ?`), so concurrent purchases are safe.

## `vipshop_purchases`

An immutable purchase log for coin transactions.

| Column                                   | Notes                                                   |
| ---------------------------------------- | ------------------------------------------------------- |
| `id`, `owner`, `player_name`             | Who                                                     |
| `product_id`, `product_name`, `quantity` | What                                                    |
| `total_price`, `currency`                | The final charged amount, after the membership discount |
| `created_at`                             | When                                                    |

## `vipshop_codes` and `vipshop_code_redemptions`

Redeem code definitions plus the per player usage ledger. The composite primary key (`code`, `owner`) guarantees one redemption per wallet.

## `vipshop_memberships`

| Column               | Notes                                                           |
| -------------------- | --------------------------------------------------------------- |
| `owner`, primary key | Wallet key                                                      |
| `tier`               | `deputy`, `marshal`, `legend`, `founder` or custom              |
| `expires_at`         | `NULL` means lifetime; expired rows clean themselves up on read |

## `vipshop_orders`

The commission book used by `order` type deliveries (no default product uses it).

| Column                 | Notes                                            |
| ---------------------- | ------------------------------------------------ |
| `id`                   | Shown in Discord and used by `vipshop_orderdone` |
| `owner`, `player_name` | The buyer                                        |
| `order_key`            | For example `custom_outfit`                      |
| `product`              | Display name                                     |
| `status`               | `open`, then `done`                              |
| `created_at`           | When                                             |

## External tables written to

| Table                       | Owning resource | When                         |
| --------------------------- | --------------- | ---------------------------- |
| `stables`                   | vorp\_stables   | Horse delivery on VORP       |
| `player_horses`             | rsg-horses      | Horse delivery on RSG        |
| `users` (the `char` column) | VORP core       | Extra character slot on VORP |

These schemas were verified against the official repositories. If you run modified forks, adjust `Config.Stables` or the delivery types accordingly.
