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

# Database

Import `install.sql` once before starting the resource. It creates six tables, all prefixed `ld_races_`:

| Table                      | Purpose                                                                                                              |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `ld_races_routes`          | Routes saved from the in-game editor (`/race_save`) — geometry, rules, rewards, everything needed to run that route. |
| `ld_races_results`         | One row per finished/DNF/DQ run — used for history and to build leaderboards.                                        |
| `ld_races_leaderboard`     | Each player's best time per route/mode/vehicle — kept in sync as new results come in.                                |
| `ld_races_stats`           | Per-player aggregate stats: races started/finished, wins, podiums, DNFs, total earnings/XP.                          |
| `ld_races_ghosts`          | Global ghost data (route path + vehicle) per route/mode/vehicle-class, for the fastest recorded run.                 |
| `ld_races_personal_ghosts` | Each player's own best-run ghost, per route.                                                                         |

You don't need to interact with these tables directly for normal operation. Routes are managed via `/racecreator` and the `race_*` admin commands (see [Admin Guide](/races/admin-guide.md)), while results, leaderboards, and ghosts are written automatically as players race.

## Backups & migrations

Back up these tables like any other player-data table.

There are no separate migration scripts. `install.sql` uses `CREATE TABLE IF NOT EXISTS`, so re-running it on an existing database is safe and won't touch existing rows.

## Multiple identifier types

`identifier` columns store whatever your framework uses as a stable player ID, such as QBCore's `citizenid` or ESX's identifier.

{% hint style="warning" %}
If you switch frameworks on an existing server, prior leaderboard, ghost, and stat rows will effectively belong to different identifiers going forward.
{% endhint %}


---

# 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.lostdev.store/races/database.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.
