# SQL Database

**moh-stoptroll** requires two tables in your MySQL database. Run the following SQL **once** before starting the resource.

***

### Full SQL Script

```sql
-- ============================================================
-- moh-stoptroll — Database Tables
-- Run this once before starting the resource
-- ============================================================

-- Stopfire sentences table
CREATE TABLE IF NOT EXISTS `stopfire_actions` (
  `id`                INT UNSIGNED     NOT NULL AUTO_INCREMENT,
  `identifier`        VARCHAR(64)      NOT NULL,
  `actions_remaining` INT              NOT NULL DEFAULT 0,
  `created_at`        TIMESTAMP        NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `identifier_unique` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Community Service sentences table
CREATE TABLE IF NOT EXISTS `communityservice` (
  `id`                INT UNSIGNED     NOT NULL AUTO_INCREMENT,
  `identifier`        VARCHAR(64)      NOT NULL,
  `actions_remaining` INT              NOT NULL DEFAULT 0,
  `created_at`        TIMESTAMP        NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `identifier_unique` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

***

### Table Descriptions

#### `stopfire_actions`

Stores active Stopfire sentences.

| Column              | Type        | Description                       |
| ------------------- | ----------- | --------------------------------- |
| `id`                | INT         | Auto-increment primary key        |
| `identifier`        | VARCHAR(64) | Player's `citizenid` from QBCore  |
| `actions_remaining` | INT         | Minutes remaining on the sentence |
| `created_at`        | TIMESTAMP   | When the sentence was created     |

#### `communityservice`

Stores active Community Service sentences.

| Column              | Type        | Description                      |
| ------------------- | ----------- | -------------------------------- |
| `id`                | INT         | Auto-increment primary key       |
| `identifier`        | VARCHAR(64) | Player's `citizenid` from QBCore |
| `actions_remaining` | INT         | Number of tasks remaining        |
| `created_at`        | TIMESTAMP   | When the sentence was created    |

***

### How to Import

#### Via phpMyAdmin

1. Open your database in phpMyAdmin
2. Click the **SQL** tab
3. Paste the full script above
4. Click **Go**

#### Via MySQL CLI

Save the SQL to a file named `stopfire_tables.sql`, then run:

```bash
mysql -u root -p your_database_name < stopfire_tables.sql
```

#### Via HeidiSQL / DBeaver

Open a new query window, paste the script, and execute.

***

### Persistence

Sentences **persist across server restarts**. When a player reconnects, the server checks the database and automatically resumes their active sentence.


---

# Agent Instructions: 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:

```
GET https://mohssins.gitbook.io/mohscriptsdocs/moh-stoptroll/sql-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
