Skip to content
Draft
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ 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
- Removed DX8/SW models that aren't used
- 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

Expand Down
56 changes: 20 additions & 36 deletions gamemodes/terrortown/gamemode/shared/sh_sql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Comment thread
ZenBre4ker marked this conversation as resolved.
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
Comment thread
ZenBre4ker marked this conversation as resolved.
else
local str = "CREATE TABLE " .. sql.SQLStr(tableName) .. " (name TEXT PRIMARY KEY"

for key, data in pairs(keys) do
Expand All @@ -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

---
Expand Down