> 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/territories/database.md).

# database

Uses [`oxmysql`](https://github.com/overextended/oxmysql). Tables are created automatically on first start—no manual SQL required, though an `install.sql` is included if you'd rather run the schema yourself ahead of time.

## `territories_data`

Current state of each territory.

| Column                | Type             | Description                                            |
| --------------------- | ---------------- | ------------------------------------------------------ |
| `id`                  | VARCHAR(50) PK   | Territory identifier.                                  |
| `owner`               | VARCHAR(50) NULL | Owning faction (`NULL` = neutral).                     |
| `progress`            | FLOAT            | Capture progress, 0-100.                               |
| `state`               | VARCHAR(20)      | `neutral` \| `capturing` \| `contested` \| `cooldown`. |
| `cooldown_start_time` | BIGINT           | Internal timer reference.                              |
| `cooldown_duration`   | BIGINT           | Cooldown duration, in seconds.                         |
| `last_update`         | TIMESTAMP        | Automatic.                                             |
| `data`                | LONGTEXT         | JSON snapshot of the same fields.                      |

## `territories_custom_zones`

Territories created in-game via the Admin panel's *Create Zone* form.

| Column        | Type             | Description                             |
| ------------- | ---------------- | --------------------------------------- |
| `id`          | VARCHAR(50) PK   | Generated from the label.               |
| `label`       | VARCHAR(100)     | Territory name.                         |
| `description` | VARCHAR(255)     |                                         |
| `coord_x/y/z` | FLOAT            | Zone center.                            |
| `radius`      | FLOAT            | Radius, in meters.                      |
| `owner`       | VARCHAR(50) NULL | Initial owner.                          |
| `created_by`  | VARCHAR(100)     | Identifier of the admin who created it. |
| `created_at`  | TIMESTAMP        |                                         |

## `territories_history`

Log of every capture/defend/lose/admin-action event. This is the single source of data for the tablet's My Faction, Statistics, History, and Activity Feed tabs—if it's empty, those tabs simply show no data yet; nothing is fabricated.

| Column           | Type                   | Description                                             |
| ---------------- | ---------------------- | ------------------------------------------------------- |
| `id`             | INT PK AUTO\_INCREMENT |                                                         |
| `territory_id`   | VARCHAR(50)            |                                                         |
| `event_type`     | VARCHAR(20)            | `captured` \| `defended` \| `lost` \| `admin_override`. |
| `faction`        | VARCHAR(50)            | Faction the event happened to.                          |
| `previous_owner` | VARCHAR(50) NULL       |                                                         |
| `is_admin`       | TINYINT(1)             | `1` if forced via the Admin panel.                      |
| `reason`         | VARCHAR(255) NULL      | Admin-supplied reason, if any.                          |
| `created_at`     | TIMESTAMP              |                                                         |

## Notes

* There is no automatic cleanup of `territories_history`—it grows over time. If you want to cap it, run a periodic:

  ```sql
  DELETE FROM territories_history WHERE created_at <
  DATE_SUB(NOW(), INTERVAL 90 DAY)
  ```

  on your own schedule.
* These tables are safe to query directly if you want to build an external dashboard, leaderboard website, or your own backups.


---

# 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/territories/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.
