Skip to content

Commit

Permalink
tweak(server): order for deleting character data
Browse files Browse the repository at this point in the history
Order for deleting character data in order to mitigate foreign key issues
  • Loading branch information
BerkieBb committed May 2, 2024
1 parent ccd258f commit 76c3921
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
38 changes: 22 additions & 16 deletions config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,32 @@ return {
}
},


---@alias TableName string
---@alias ColumnName string
---@type table<TableName, ColumnName>
---@type [TableName, ColumnName][]
characterDataTables = {
players = 'citizenid',
apartments = 'citizenid',
bank_accounts_new = 'id',
crypto_transactions = 'citizenid',
phone_invoices = 'citizenid',
phone_messages = 'citizenid',
playerskins = 'citizenid',
player_contacts = 'citizenid',
player_houses = 'citizenid',
player_mails = 'citizenid',
player_outfits = 'citizenid',
player_vehicles = 'citizenid',
{'properties', 'owner'},
{'apartments', 'citizenid'},
{'bank_accounts_new', 'id'},
{'crypto_transactions', 'citizenid'},
{'phone_invoices', 'citizenid'},
{'phone_messages', 'citizenid'},
{'playerskins', 'citizenid'},
{'player_contacts', 'citizenid'},
{'player_houses', 'citizenid'},
{'player_mails', 'citizenid'},
{'player_outfits', 'citizenid'},
{'player_vehicles', 'citizenid'},
{'players', 'citizenid'},
{'npwd_calls', 'identifier'},
{'npwd_darkchat_channel_members', 'user_identifier'},
{'npwd_marketplace_listings', 'identifier'},
{'npwd_messages_participants', 'participant'},
{'npwd_notes', 'identifier'},
{'npwd_phone_contacts', 'identifier'},
{'npwd_phone_gallery', 'identifier'},
}, -- Rows to be deleted when the character is deleted


server = {
pvp = true, -- Enable or disable pvp on the server (Ability to shoot other players)
closed = false, -- Set server closed (no one can join except people with ace permission 'qbadmin.join')
Expand Down Expand Up @@ -134,4 +140,4 @@ return {
removeSocietyMoney = function(accountName, payment)
return exports['Renewed-Banking']:removeAccountMoney(accountName, payment)
end,
}
}
8 changes: 6 additions & 2 deletions server/storage/players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ local function deletePlayer(citizenId)
local query = 'DELETE FROM %s WHERE %s = ?'
local queries = {}

for tableName, columnName in pairs(characterDataTables) do
for i = 1, #characterDataTables do
local data = characterDataTables[i]
local tableName = data[1]
local columnName = data[2]
if doesTableExist(tableName) then
queries[#queries + 1] = {
query = query:format(tableName, columnName),
Expand Down Expand Up @@ -359,7 +362,8 @@ RegisterCommand('convertjobs', function(source)
end, true)

CreateThread(function()
for tableName in pairs(characterDataTables) do
for _, data in pairs(characterDataTables) do
local tableName = data[1]
if not doesTableExist(tableName) then
warn(('Table \'%s\' does not exist in database, please remove it from qbx_core/config/server.lua or create the table'):format(tableName))
end
Expand Down

0 comments on commit 76c3921

Please sign in to comment.