# Installation

## Database Installation

{% hint style="danger" %}
1. Before installing the m-Garages please make a backup of your entire database.
2. The script will attempt to migrate your existing vehicles automatically.&#x20;
3. When starting the script for the first time, you might see some errors, simply restart and test again.
4. You can enable the **install\_sql\_on\_startup** option inside **config.lua**.
{% endhint %}

{% tabs %}
{% tab title="QBCore" %}
```sql
CREATE TABLE
    IF NOT EXISTS `m_garages_private_garages` (
        `id` int (11) unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(255) DEFAULT NULL,
        `type` varchar(50) DEFAULT NULL,
        `radius` int (11) DEFAULT 10,
        `coords_x` float DEFAULT NULL,
        `coords_y` float DEFAULT NULL,
        `coords_z` float DEFAULT NULL,
        `coords_w` float DEFAULT NULL,
        `spawn_x` float NOT NULL,
        `spawn_y` float NOT NULL,
        `spawn_z` float NOT NULL,
        `spawn_w` float NOT NULL,
        PRIMARY KEY (`id`),
        UNIQUE KEY `name` (`name`)
    );

CREATE TABLE
    IF NOT EXISTS `m_garages_private_garages_owners` (
        `char_id` varchar(255) NOT NULL,
        `garage_id` int (11) unsigned NOT NULL,
        `name` varchar(50) NOT NULL DEFAULT 'UNKNOWN',
        UNIQUE KEY `char_id_garage_id` (`char_id`, `garage_id`),
        KEY `garage_owner_fk` (`garage_id`),
        CONSTRAINT `garage_owner_fk` FOREIGN KEY (`garage_id`) REFERENCES `m_garages_private_garages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    );

CREATE TABLE
    IF NOT EXISTS `m_garages_vehicle_spawners` (
        `id` int (11) unsigned NOT NULL AUTO_INCREMENT,
        `job` varchar(255) DEFAULT NULL,
        `gang` varchar(255) DEFAULT NULL,
        `grade` int (11) NOT NULL DEFAULT 0,
        `nickname` varchar(255) NOT NULL,
        `model` varchar(255) NOT NULL,
        `mods` longtext NOT NULL,
        `vehicle_type` varchar(255) NOT NULL,
        `garage_type` enum ('car', 'air', 'sea') NOT NULL,
        `custom_plate` varchar(8) DEFAULT NULL,
        `spawn_limit` int (11) NOT NULL DEFAULT -1,
        PRIMARY KEY (`id`),
        UNIQUE KEY `job_model` (`model`, `job`) USING BTREE,
        UNIQUE KEY `gang_model` (`model`, `gang`),
        KEY `gang` (`gang`),
        KEY `job` (`job`)
    );

-- player_vehicles
ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `fuel` INT (10) DEFAULT '100';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `engine` INT (10) DEFAULT '1000';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `body` INT (10) DEFAULT '1000';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `nickname` VARCHAR(255) DEFAULT '';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `impound_data` LONGTEXT DEFAULT '';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `impound_data` longtext DEFAULT '';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `impounded_at` datetime DEFAULT NULL;

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `impounded_retrievable_at` datetime DEFAULT NULL;

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `vehicle_type` enum (
    'automobile',
    'bike',
    'boat',
    'heli',
    'plane',
    'submarine',
    'trailer',
    'train'
) NOT NULL DEFAULT 'automobile';

ALTER TABLE `player_vehicles`
ADD COLUMN IF NOT EXISTS `metadata` longtext DEFAULT NULL;
```
{% endtab %}

{% tab title="ESX" %}
```sql
CREATE TABLE
    IF NOT EXISTS `m_garages_private_garages` (
        `id` int (11) unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(255) DEFAULT NULL,
        `type` varchar(50) DEFAULT NULL,
        `radius` int (11) DEFAULT 10,
        `coords_x` float DEFAULT NULL,
        `coords_y` float DEFAULT NULL,
        `coords_z` float DEFAULT NULL,
        `coords_w` float DEFAULT NULL,
        `spawn_x` float NOT NULL,
        `spawn_y` float NOT NULL,
        `spawn_z` float NOT NULL,
        `spawn_w` float NOT NULL,
        PRIMARY KEY (`id`),
        UNIQUE KEY `name` (`name`)
    );

CREATE TABLE
    IF NOT EXISTS `m_garages_private_garages_owners` (
        `char_id` varchar(255) NOT NULL,
        `garage_id` int (11) unsigned NOT NULL,
        `name` varchar(50) NOT NULL DEFAULT 'UNKNOWN',
        UNIQUE KEY `char_id_garage_id` (`char_id`, `garage_id`),
        KEY `garage_owner_fk` (`garage_id`),
        CONSTRAINT `garage_owner_fk` FOREIGN KEY (`garage_id`) REFERENCES `m_garages_private_garages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    );

CREATE TABLE
    IF NOT EXISTS `m_garages_vehicle_spawners` (
        `id` int (11) unsigned NOT NULL AUTO_INCREMENT,
        `job` varchar(255) DEFAULT NULL,
        `gang` varchar(255) DEFAULT NULL,
        `grade` int (11) NOT NULL DEFAULT 0,
        `nickname` varchar(255) NOT NULL,
        `model` varchar(255) NOT NULL,
        `mods` longtext NOT NULL,
        `vehicle_type` varchar(255) NOT NULL,
        `garage_type` enum ('car', 'air', 'sea') NOT NULL,
        `custom_plate` varchar(8) DEFAULT NULL,
        `spawn_limit` int (11) NOT NULL DEFAULT -1,
        PRIMARY KEY (`id`),
        UNIQUE KEY `job_model` (`model`, `job`) USING BTREE,
        UNIQUE KEY `gang_model` (`model`, `gang`),
        KEY `gang` (`gang`),
        KEY `job` (`job`)
    );

-- player_vehicles
ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `parking` varchar(255) DEFAULT NULL;

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `fuel` INT (10) DEFAULT '100';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `engine` INT (10) DEFAULT '1000';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `body` INT (10) DEFAULT '1000';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `nickname` VARCHAR(255) DEFAULT '';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `impound_data` LONGTEXT DEFAULT '';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `impound_data` longtext DEFAULT '';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `impounded_at` datetime DEFAULT NULL;

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `impounded_retrievable_at` datetime DEFAULT NULL;

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `vehicle_type` enum (
    'automobile',
    'bike',
    'boat',
    'heli',
    'plane',
    'submarine',
    'trailer',
    'train'
) NOT NULL DEFAULT 'automobile';

ALTER TABLE `owned_vehicles`
ADD COLUMN IF NOT EXISTS `metadata` longtext DEFAULT NULL;
```
{% endtab %}
{% endtabs %}

## Dependencies

* [ox\_lib](https://github.com/overextended/ox_lib)
* [oxmysql](https://github.com/overextended/oxmysql)
* [Server Build 10300+](https://runtime.fivem.net/artifacts/fivem/build_server_windows/master/)
* [MariaDB database](https://mariadb.com/downloads/)
