Add optional name history migration for sa_players_ips

SimpleAdmin upserts sa_players_ips on (steamid, address), so a rename on
the same IP overwrites the old name. sql/players-ips-name-history.sql adds
name to the primary key (binary collation, NOT NULL), so every name a
SteamID joins with is kept and shows on its player page and in name
search. SimpleAdmin's IP cache keeps only the newest row per IP, so its
multi-account and IP-ban checks are unchanged. The file includes a revert.
This commit is contained in:
Astra 2026-09-27 15:37:37 +01:00
parent b579941964
commit 657ead4c5a
2 changed files with 38 additions and 0 deletions

View file

@ -82,6 +82,14 @@ SimpleAdmin groups have no display name or colour, so those come from a site con
`"supporter": true` are listed apart from staff and can't sign in unless they hold
`@css/generic`.
### Name history (optional)
SimpleAdmin keeps one row per SteamID + IP in `sa_players_ips` and overwrites its name on each
connect, so a rename on the same IP loses the old name. `sql/players-ips-name-history.sql` adds
`name` to that table's primary key, so every name a SteamID has joined with is kept and shows up
on its player page and in name search. SimpleAdmin needs no changes. Run it once against the
SimpleAdmin database; the file has the revert. Names are still only recorded at connect.
## Limitations and caveats
- **Tested against a real MySQL 8.4** with SimpleAdmin 1.8.2b's migrations applied, and a fake game

View file

@ -0,0 +1,30 @@
-- Keep every name a SteamID has used, instead of overwriting it.
--
-- CS2-SimpleAdmin records each connect with an upsert keyed on sa_players_ips' primary key,
-- (steamid, address), so a player who rejoins from the same IP under a new name overwrites the old
-- name. With name in the key, a new name on the same SteamID+IP is a new row; the same name again
-- still just bumps used_at. SimpleAdmin's own code is unchanged: its IP cache already keeps only
-- the newest row per IP, so multi-account and IP-ban checks behave as before.
--
-- name becomes binary-collated so a case-only rename ("astra" -> "Astra") is also kept, and NOT
-- NULL because primary key columns can't be NULL (SimpleAdmin always writes a name).
--
-- Only records names at connect, like before: a rename mid-session shows up on the next join.
-- Re-check after upgrading SimpleAdmin, in case a later migration rebuilds this table's key.
UPDATE sa_players_ips SET name = '' WHERE name IS NULL;
ALTER TABLE sa_players_ips
MODIFY name VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '',
DROP PRIMARY KEY,
ADD PRIMARY KEY (steamid, address, name);
-- Revert (drops the older names, keeping the newest row per SteamID+IP):
--
-- DELETE a FROM sa_players_ips a JOIN sa_players_ips b
-- ON a.steamid = b.steamid AND a.address = b.address
-- AND (a.used_at < b.used_at OR (a.used_at = b.used_at AND a.name < b.name));
-- ALTER TABLE sa_players_ips
-- DROP PRIMARY KEY,
-- ADD PRIMARY KEY (steamid, address),
-- MODIFY name VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;