# Database

Koja Inventory creates its tables with `CREATE TABLE IF NOT EXISTS` every time it starts. There is no SQL file to import, and nothing in the upstream `ox_inventory` table changes.

## Tables

| Table | What is in it |
| --- | --- |
| `koja_inv_items` | Items created or edited on the admin **Items** pages (`name`, `data` as JSON) |
| `koja_inv_rarities` | Rarities edited on **Edit Rarity** |
| `koja_inv_shops` | Shops created or edited on **Shops** |
| `koja_inv_stashes` | Stashes created or edited on **Stashes** |
| `koja_inv_crafting` | Crafting benches created or edited on **Crafting benches** |
| `koja_inv_roles` | Staff roles and their page permissions |
| `koja_inv_staff` | Staff members: `identifier`, `name`, `role`, `last_seen` |
| `koja_inv_locales` | String overrides from **Locales** (`lang`, `k`, `v`) |
| `koja_inv_settings` | Panel settings: addon toggles (`features`), ped preview mode (`pedMode`), world containers (`containers`), clothing (`clothing`), security (`security`) |
| `koja_inv_history` | The inventory history: time, action, actor, from / to inventory, item, count, slot, serial, metadata |
| `koja_inv_security` | Security reports: time, player, kind, detail |
| `koja_inv_attachment_offsets` | Marker offsets of the 3D attachments view per weapon and component |

Values in these tables override the matching `data/` files. Delete a row (or use the panel's restore / reset buttons) to go back to the file.

## Worn clothes and mini stashes

These are normal ox_inventory inventories, saved in the upstream `ox_inventory` table like stashes:

| Inventory id | What it holds |
| --- | --- |
| `koja_clothes:<identifier>` | The clothes a character wears, one slot per clothing slot |
| `koja_mini_<serial>` | The contents of one mini stash or hanger, keyed by the item's serial number |

They are private: players cannot open them by id.

## History cleanup

History rows older than `history.retentionDays` (30 days) are deleted on start and every 6 hours. Set it to `0` to keep everything. To exclude noisy actions, add them to `history.ignore`:

```lua title="data/koja/admin.lua"
history = {
    retentionDays = 14,
    ignore = { open = true, close = true },
},
```
