From ade30bdec03d32bda35ed30926aba53a5eb85e7f Mon Sep 17 00:00:00 2001 From: Antony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:42:16 +0100 Subject: [PATCH 1/3] feat: update the constraints & remove financing columns --- server/main.lua | 4 ---- vehicles.sql | 16 ++++++---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/server/main.lua b/server/main.lua index 731c724..4240758 100644 --- a/server/main.lua +++ b/server/main.lua @@ -21,10 +21,6 @@ local State = { ---@field depotprice number ---@field drivingdistance number ---@field status string ----@field balance number ----@field paymentamount number ----@field paymentsleft number ----@field financetime number ---@class CreateEntityQuery ---@field citizenId string The citizen id of the owner diff --git a/vehicles.sql b/vehicles.sql index d5f7c00..056dedb 100644 --- a/vehicles.sql +++ b/vehicles.sql @@ -5,9 +5,9 @@ CREATE TABLE IF NOT EXISTS `player_vehicles` ( `vehicle` varchar(50) DEFAULT NULL, `hash` varchar(50) DEFAULT NULL, `mods` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, - `plate` varchar(50) NOT NULL, + `plate` varchar(15) NOT NULL, `fakeplate` varchar(50) DEFAULT NULL, - `garage` varchar(50) DEFAULT NULL, + `garage` varchar(50) DEFAULT 'pillboxgarage', `fuel` int(11) DEFAULT 100, `engine` float DEFAULT 1000, `body` float DEFAULT 1000, @@ -15,12 +15,8 @@ CREATE TABLE IF NOT EXISTS `player_vehicles` ( `depotprice` int(11) NOT NULL DEFAULT 0, `drivingdistance` int(50) DEFAULT NULL, `status` text DEFAULT NULL, - `balance` int(11) NOT NULL DEFAULT 0, - `paymentamount` int(11) NOT NULL DEFAULT 0, - `paymentsleft` int(11) NOT NULL DEFAULT 0, - `financetime` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - KEY `plate` (`plate`), - KEY `citizenid` (`citizenid`), - KEY `license` (`license`) -) ENGINE=InnoDB AUTO_INCREMENT=1; + UNIQUE KEY `plate` (`plate`), + FOREIGN KEY (`citizenid`) REFERENCES `players` (`citizenid`) ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (`license`) REFERENCES `players` (`license`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file From e0b86c8177f5e1659c6022b2aae311833bae77aa Mon Sep 17 00:00:00 2001 From: Antony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:00:25 +0100 Subject: [PATCH 2/3] Update vehicles.sql --- vehicles.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vehicles.sql b/vehicles.sql index 056dedb..779b301 100644 --- a/vehicles.sql +++ b/vehicles.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `player_vehicles` ( `mods` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, `plate` varchar(15) NOT NULL, `fakeplate` varchar(50) DEFAULT NULL, - `garage` varchar(50) DEFAULT 'pillboxgarage', + `garage` varchar(50) DEFAULT NULL, `fuel` int(11) DEFAULT 100, `engine` float DEFAULT 1000, `body` float DEFAULT 1000, @@ -19,4 +19,4 @@ CREATE TABLE IF NOT EXISTS `player_vehicles` ( UNIQUE KEY `plate` (`plate`), FOREIGN KEY (`citizenid`) REFERENCES `players` (`citizenid`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`license`) REFERENCES `players` (`license`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; From 9ddd0964af993253dc117cd451c04bb038157c68 Mon Sep 17 00:00:00 2001 From: Antony <97451137+TonybynMp4@users.noreply.github.com> Date: Sat, 2 Mar 2024 19:26:09 +0100 Subject: [PATCH 3/3] return vehicleId on CreateEntity & add DeleteById --- server/main.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/main.lua b/server/main.lua index 4240758..f8d6ccc 100644 --- a/server/main.lua +++ b/server/main.lua @@ -31,8 +31,9 @@ local State = { --- Creates a Vehicle DB Entity ---@param query CreateEntityQuery +---@return vehicleId integer local function createEntity(query) - MySQL.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES ((SELECT license FROM players WHERE citizenid = ?),?,?,?,?,?,?)', { + return MySQL.insert.await('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state) VALUES ((SELECT license FROM players WHERE citizenid = ?),?,?,?,?,?,?)', { query.citizenId, query.citizenId, query.model, @@ -129,6 +130,14 @@ end exports('DeleteEntityByPlate', deleteEntityByPlate) +--- Deletes a DB Vehicle Entity through searching for the vehicle id +---@param id integer +local function deleteEntityById(id) + MySQL.query('DELETE FROM player_vehicles WHERE id = ?', {id}) +end + +exports('DeleteEntityById', deleteEntityById) + --- Returns if the given plate exists ---@param plate string ---@return boolean