From 7657ddbd50e5e8c224eaf63cbc752955a8708ecc Mon Sep 17 00:00:00 2001 From: Houmgaor Date: Mon, 16 Mar 2026 00:04:45 +0100 Subject: [PATCH] fix: prevent startup panics on databases missing base tables The catch-up migration now creates the servers table if missing, like sign_sessions. Startup cleanup queries in main.go use Exec instead of MustExec so missing tables log warnings rather than panicking. --- main.go | 12 +++++++++--- server/migrations/sql/0002_catch_up_patches.sql | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 664bf83b1..c96d814e7 100644 --- a/main.go +++ b/main.go @@ -240,11 +240,17 @@ func main() { if len(ownedServerIDs) > 0 { idList := strings.Join(ownedServerIDs, ",") if config.DebugOptions.ProxyPort == 0 { - _ = db.MustExec("DELETE FROM sign_sessions WHERE server_id IN (" + idList + ")") + if _, err := db.Exec("DELETE FROM sign_sessions WHERE server_id IN (" + idList + ")"); err != nil { + logger.Warn("Failed to clear stale sign sessions", zap.Error(err)) + } + } + if _, err := db.Exec("DELETE FROM servers WHERE server_id IN (" + idList + ")"); err != nil { + logger.Warn("Failed to clear stale server entries", zap.Error(err)) } - _ = db.MustExec("DELETE FROM servers WHERE server_id IN (" + idList + ")") } - _ = db.MustExec(`UPDATE guild_characters SET treasure_hunt=NULL`) + if _, err := db.Exec(`UPDATE guild_characters SET treasure_hunt=NULL`); err != nil { + logger.Warn("Failed to reset treasure hunts", zap.Error(err)) + } // Clean the DB if the option is on. if config.DebugOptions.CleanDB { diff --git a/server/migrations/sql/0002_catch_up_patches.sql b/server/migrations/sql/0002_catch_up_patches.sql index 48abecc38..7fb0ec04f 100644 --- a/server/migrations/sql/0002_catch_up_patches.sql +++ b/server/migrations/sql/0002_catch_up_patches.sql @@ -14,6 +14,19 @@ -- 20-reset-warehouses — destructive data reset (NULLs all item_box columns) +------------------------------------------------------------------------ +-- Ensure tables that predate the patch series exist. These were always +-- part of the base schema but may be missing from very old databases. +------------------------------------------------------------------------ +CREATE TABLE IF NOT EXISTS public.servers ( + server_id integer NOT NULL, + current_players integer NOT NULL, + world_name text, + world_description text, + land integer +); + + ------------------------------------------------------------------------ -- Patch 00: psn-id (sign_sessions primary key + psn columns) ------------------------------------------------------------------------