diff --git a/CHANGELOG.md b/CHANGELOG.md index b47f03a733..23e560e8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,10 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed the scoreboard being stuck open sometimes if the inflictor was no weapon (by @TimGoll) - Fixed door health displaying as a humongous string of decimals +### Deprecated + +- Deprecated `sql.CreateSqlTable`, use migrations to manage database schemas instead + ### Removed - Removed some crosshair related convars and replaced them with other ones, see the crosshair settings menu for details @@ -115,6 +119,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Removed the convar `ttt_damage_own_healthstation` as it was inconsistent and probably unused as well - Removed `ttt_fire_fallback`, there's no situation where the fire shouldn't draw anymore. - Removed `resource.AddFile` calls, server operators should use the workshop version or manually bundle loose files. +- Removed ability to add columns on existing database table through `sql.CreateSqlTable` ### Breaking Changes diff --git a/gamemodes/terrortown/gamemode/shared/sh_sql.lua b/gamemodes/terrortown/gamemode/shared/sh_sql.lua index 245568f7f4..79dafa5bf4 100644 --- a/gamemodes/terrortown/gamemode/shared/sh_sql.lua +++ b/gamemodes/terrortown/gamemode/shared/sh_sql.lua @@ -233,11 +233,26 @@ end -- @param table keys the keys for the data @{table} -- @return boolean Whether the database table was created successfully -- @realm shared --- @todo usage +-- @deprecated function sql.CreateSqlTable(tableName, keys) - local result - - if not sql.TableExists(tableName) then + Dev( + 2, + "`sql.CreateSqlTable` is deprecated and should be handled by migrations.", + "This ran for table:", + tableName + ) + if sql.TableExists(tableName) then + Dev( + 2, + "The database table", + tableName, + "already exists.", + "Adding columns to an existing database table via `sql.CreateSqlTable` was removed." + ) + -- We need to return true here to not break our current assumptions + -- in our current codebase (database library, roleselection, huds) + return true + else local str = "CREATE TABLE " .. sql.SQLStr(tableName) .. " (name TEXT PRIMARY KEY" for key, data in pairs(keys) do @@ -246,39 +261,8 @@ function sql.CreateSqlTable(tableName, keys) str = str .. ")" - result = sql.Query(str) - else - local clmns = sql.Query("PRAGMA table_info(" .. sql.SQLStr(tableName) .. ")") - - for key, data in pairs(keys) do - local exists = false - - for i = 1, #clmns do - if clmns[i].name ~= key then - continue - end - - exists = true - end - - if exists then - continue - end - - local res = sql.ParseDataString(key, data) - if not res then - continue - end - - local resArr = string.Explode(",", res) - - for i = 1, #resArr do - sql.Query("ALTER TABLE " .. sql.SQLStr(tableName) .. " ADD " .. resArr[i]) - end - end + return sql.Query(str) ~= false end - - return result ~= false end ---