# Database

Koja Appearance keeps every upstream illenium-appearance table (`playerskins`, `player_outfits`, `player_outfit_codes`, `management_outfits`, and `users.skin` on ESX) exactly as it is.
It adds three tables of its own, created automatically when the resource starts.

To create them by hand, import `sql/koja_appearance.sql`.
For a fresh server without illenium-appearance, also import the other files in `sql/`.

## koja_appearance_assets

One row per captured item: its name, price and image URL.

| Column | Type | Description |
| --- | --- | --- |
| `gender` | `VARCHAR(10)` | `male` or `female` |
| `category` | `VARCHAR(32)` | Category key, e.g. `jackets` or `tattoo_torso` |
| `item_key` | `VARCHAR(64)` | `drawable` or `drawable_texture`, or the tattoo name key |
| `name` | `VARCHAR(64)` | Name from the Capture panel. `NULL` = default name |
| `price` | `INT` | Price from the Capture panel. `NULL` = auto price or `DefaultPrice` |
| `url` | `VARCHAR(512)` | Fivemanage URL. `NULL` = the file in `shots/` |
| `updated_at` | `INT` | Unix time of the last change, added to the image URL so players get the new image |

Primary key: `gender`, `category`, `item_key`.

## koja_appearance_categories

Capture settings per category and gender.

| Column | Type | Description |
| --- | --- | --- |
| `gender` | `VARCHAR(10)` | `male` or `female` |
| `category` | `VARCHAR(32)` | Category key |
| `with_textures` | `TINYINT(1)` | `1` = one image per texture variant |
| `offsets` | `LONGTEXT` | JSON camera preset: `fov`, `height`, `rotation`, `distance` |
| `hide` | `LONGTEXT` | JSON list of ped parts hidden while shooting |

## koja_appearance_settings

Key / value settings of the Capture panel, such as the storage mode and the Fivemanage API key.

| Column | Type | Description |
| --- | --- | --- |
| `k` | `VARCHAR(64)` | Setting name |
| `v` | `TEXT` | Value |

:::hint{type="warning" title="Keep it private"}
The Fivemanage API key is stored here. Do not share database dumps of this table.
:::

## koja_appearance_skin_backup (ESX)

Created on ESX when `Config.Koja.AutoMigrateESXSkins = true`.
Before an old `esx_skin` / `skinchanger` skin in `users.skin` is converted to the appearance format, the original is copied here.

| Column | Type | Description |
| --- | --- | --- |
| `identifier` | `VARCHAR(64)` | Player identifier (primary key) |
| `skin` | `LONGTEXT` | The original skin JSON |
| `backed_up_at` | `INT` | Unix time of the backup |

A skin is backed up only once; running the conversion again never overwrites the first backup.

## Per-player Studio settings

The Studio settings (theme, light, studio, pose) are not stored in the database.
They are saved on each player's PC in the client KVP key `Config.Koja.PrefsKvp` (`koja_appearance_prefs`).
