From 297a169d16ca987eb9f474fa4a8cc780ea203a3e Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 31 Aug 2025 15:17:51 +0200 Subject: [PATCH] fix(es_extended/server/migration): only require restart if actually neccessary --- [core]/es_extended/server/migration/main.lua | 18 ++++++++++++------ .../server/migration/v1.13.3/ssn/main.lua | 5 ++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/[core]/es_extended/server/migration/main.lua b/[core]/es_extended/server/migration/main.lua index c5f226c4..378894fd 100644 --- a/[core]/es_extended/server/migration/main.lua +++ b/[core]/es_extended/server/migration/main.lua @@ -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 diff --git a/[core]/es_extended/server/migration/v1.13.3/ssn/main.lua b/[core]/es_extended/server/migration/v1.13.3/ssn/main.lua index 0beee7aa..83b36e9b 100644 --- a/[core]/es_extended/server/migration/v1.13.3/ssn/main.lua +++ b/[core]/es_extended/server/migration/v1.13.3/ssn/main.lua @@ -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