Skip to content

Commit 6faef18

Browse files
authored
refactor(seeder): route dev-DB seeder onto LogType / BanRemoval backed enums (sbpp#1483) (sbpp#1485)
Replace magic letter codes in `web/tests/Synthesizer.php` with the project's column-typed backed-enum wrappers per AGENTS.md → "Backed enums for column-typed fields": > always pass `$enum->value` (not the enum case itself) so the dba > plugin and the underlying PDO see the column-typed primitive Three concrete sites: - `insertBans()` admin-removed branch: `'U'` / `'D'` literals → `BanRemoval::Unbanned->value` / `BanRemoval::Deleted->value`. - `insertComms()` admin-removed branch: `'U'` literal → `BanRemoval::Unbanned->value`. - `insertAuditLog()` events table: `'m'` / `'w'` / `'e'` first-column literals → `LogType::Message->value` / `LogType::Warning->value` / `LogType::Error->value` (lifted to local variables so the 20-row events table stays readable + the enum lookup happens once per call). The change is pure refactor — no RNG draws shifted (the new `mt_rand(0, 1)` arms still resolve to the same `'U'` / `'D'` strings via the enum's `->value`), so `Synthesizer::DEFAULT_SEED` reproduces byte-identical row distributions before / after (verified by re-running the seeder twice against the dev DB and diffing the resulting RemoveType + log.type counts). Out of scope per the issue body: `comments.type` (would need a new `CommentType` enum), `demos.demtype` (would need a new `DemoType` enum), and `bans.type` (`BanType` exists but the seeder uses an explicit `$isIpOnly` boolean + writes 0 / 1 directly — explicitly listed under "Out of scope" in the issue).
1 parent 424d6d4 commit 6faef18

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

web/tests/Synthesizer.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ private function insertBans(): int
824824
}
825825
} else {
826826
// Admin-removed (~15%).
827-
$removeType = mt_rand(0, 1) === 0 ? 'U' : 'D';
827+
$removeType = mt_rand(0, 1) === 0
828+
? \BanRemoval::Unbanned->value
829+
: \BanRemoval::Deleted->value;
828830
$removedBy = $this->randomAdminAid();
829831
$removedOn = $created + mt_rand(60 * 60, 60 * 60 * 24 * 7);
830832
if ($removedOn > $this->now) {
@@ -940,7 +942,7 @@ private function insertComms(): int
940942
$ends = $created + $length;
941943
}
942944
} else {
943-
$removeType = 'U';
945+
$removeType = \BanRemoval::Unbanned->value;
944946
$removedBy = $this->randomAdminAid();
945947
$removedOn = $created + mt_rand(60, 60 * 60 * 24);
946948
if ($removedOn > $this->now) {
@@ -1225,27 +1227,30 @@ private function insertAuditLog(): int
12251227
));
12261228
// Mix of action types so the audit log filter dropdown
12271229
// (admin / message / type / date) has something to match.
1230+
$messageType = \LogType::Message->value;
1231+
$warningType = \LogType::Warning->value;
1232+
$errorType = \LogType::Error->value;
12281233
$events = [
1229-
['m', 'Ban Added', 'admin added a ban for player'],
1230-
['m', 'Ban Edited', 'admin edited a ban'],
1231-
['m', 'Ban Unbanned', 'admin unbanned a player'],
1232-
['m', 'Comment Added', 'admin added a comment for ban'],
1233-
['m', 'Comment Edited', 'admin edited comment'],
1234-
['m', 'Server Added', 'admin added server'],
1235-
['m', 'Server Edited', 'admin edited server'],
1236-
['m', 'Mod Added', 'admin added mod'],
1237-
['m', 'Group Added', 'admin added group'],
1238-
['m', 'Group Edited', 'admin edited group'],
1239-
['m', 'Admin Added', 'admin added admin'],
1240-
['m', 'Admin Edited', 'admin edited admin'],
1241-
['m', 'Setting Updated', 'admin updated setting'],
1242-
['m', 'Submission Archived', 'admin archived submission'],
1243-
['m', 'Protest Archived', 'admin archived protest'],
1244-
['w', 'Ban Failed', 'failed to add ban: server unreachable'],
1245-
['w', 'RCON Failed', 'rcon command timed out'],
1246-
['w', 'Permission Denied', 'admin attempted action without flag'],
1247-
['e', 'Database Error', 'unexpected SQL state'],
1248-
['e', 'Auth Failure', 'invalid login attempt'],
1234+
[$messageType, 'Ban Added', 'admin added a ban for player'],
1235+
[$messageType, 'Ban Edited', 'admin edited a ban'],
1236+
[$messageType, 'Ban Unbanned', 'admin unbanned a player'],
1237+
[$messageType, 'Comment Added', 'admin added a comment for ban'],
1238+
[$messageType, 'Comment Edited', 'admin edited comment'],
1239+
[$messageType, 'Server Added', 'admin added server'],
1240+
[$messageType, 'Server Edited', 'admin edited server'],
1241+
[$messageType, 'Mod Added', 'admin added mod'],
1242+
[$messageType, 'Group Added', 'admin added group'],
1243+
[$messageType, 'Group Edited', 'admin edited group'],
1244+
[$messageType, 'Admin Added', 'admin added admin'],
1245+
[$messageType, 'Admin Edited', 'admin edited admin'],
1246+
[$messageType, 'Setting Updated', 'admin updated setting'],
1247+
[$messageType, 'Submission Archived', 'admin archived submission'],
1248+
[$messageType, 'Protest Archived', 'admin archived protest'],
1249+
[$warningType, 'Ban Failed', 'failed to add ban: server unreachable'],
1250+
[$warningType, 'RCON Failed', 'rcon command timed out'],
1251+
[$warningType, 'Permission Denied', 'admin attempted action without flag'],
1252+
[$errorType, 'Database Error', 'unexpected SQL state'],
1253+
[$errorType, 'Auth Failure', 'invalid login attempt'],
12491254
];
12501255
for ($i = 0; $i < $count; $i++) {
12511256
$ev = $events[mt_rand(0, count($events) - 1)];

0 commit comments

Comments
 (0)