Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update the constraints & remove financing columns #3

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,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,
Expand Down Expand Up @@ -133,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
Expand Down
14 changes: 5 additions & 9 deletions vehicles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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,
`fuel` int(11) DEFAULT 100,
Expand All @@ -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`),
mafewtm marked this conversation as resolved.
Show resolved Hide resolved
FOREIGN KEY (`citizenid`) REFERENCES `players` (`citizenid`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`license`) REFERENCES `players` (`license`) ON DELETE CASCADE ON UPDATE CASCADE
Manason marked this conversation as resolved.
Show resolved Hide resolved
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Loading