fix(es_extended/server/migration): only require restart if actually neccessary

This commit is contained in:
Kenshin13
2025-08-31 15:17:51 +02:00
committed by _Not_
parent 2242bdef75
commit 297a169d16
2 changed files with 16 additions and 7 deletions
+12 -6
View File
@@ -11,6 +11,7 @@ RegisterCommand("resetmigrations", function(src)
end)
local migrationsRan = 0
local restartRequired = false
for esxVersion, migrations in pairs(Core.Migrations or {}) do
---@cast esxVersion string
@@ -20,10 +21,17 @@ for esxVersion, migrations in pairs(Core.Migrations or {}) do
print(("^4[INFO]^7 Running migrations for ESX version %s"):format(esxVersion))
for migrationName, migration in pairs(migrations) do
local success, err = pcall(migration)
local success, result = pcall(migration)
if not success then
local err = result --[[@as string]]
error(("^1[ERROR]^7 Failed migration ^4['%s.%s']^7: %s"):format(esxVersion, migrationName, err))
end
local migrationRequiresRestart = result --[[@as boolean]]
if not restartRequired and migrationRequiresRestart then
restartRequired = true
end
end
SetResourceKvpInt(("esx_migration:%s"):format(esxVersion), 1)
@@ -32,9 +40,7 @@ for esxVersion, migrations in pairs(Core.Migrations or {}) do
end
end
if migrationsRan > 0 then
while true do
print(("^4[INFO]^7 Ran migrations for %d ESX version(s). ^1Server restart required!^7"):format(migrationsRan))
Wait(500)
end
while restartRequired do
print(("^4[INFO]^7 Ran migrations for %d ESX version(s). ^1Server restart required!^7"):format(migrationsRan))
Wait(500)
end
@@ -7,6 +7,7 @@ if GetResourceKvpInt(("esx_migration:%s"):format(esxVersion)) == 1 then
return
end
---@return boolean restartRequired
Core.Migrations[esxVersion].ssn = function()
print("^4[esx_migration:v.1.13.3:ssn]^7 Adding SSN column to users table.")
local col = MySQL.scalar.await([[
@@ -41,7 +42,7 @@ Core.Migrations[esxVersion].ssn = function()
local Result = MySQL.query.await("SELECT `identifier` FROM `users` WHERE `ssn` IS NULL")
if #Result == 0 then
print("^4[esx_migration:v.1.13.3:ssn]^7 No users found without SSN, migration not needed.")
return
return false
end
print("^4[esx_migration:v.1.13.3:ssn]^7 Generating SSN for existing users.")
@@ -64,4 +65,6 @@ Core.Migrations[esxVersion].ssn = function()
MySQL.update.await("ALTER TABLE `users` MODIFY `ssn` VARCHAR(11) NOT NULL")
print(("^4[esx_migration:v.1.13.3:ssn]^7 Successfully migrated %d users."):format(#Parameters))
return true
end