Support multi-game betas with automatic server selection

This commit is contained in:
2026-10-07 09:41:17 -04:00
parent a6dee8c5e2
commit c6352d86b4
17 changed files with 881 additions and 173 deletions
+5 -4
View File
@@ -125,9 +125,8 @@ function migrateTable(handle: Database.Database, table: string, cols: Array<{ na
}
// Backfill the multi-script join tables from the legacy single-script columns.
// Idempotent — every INSERT is guarded by a NOT EXISTS clause on the target
// row's primary key. Safe to run on every boot even after the deprecated
// columns are eventually dropped.
// Existing bundle membership is authoritative. Only single-script betas can
// inherit server membership from the deprecated primary-script columns.
function backfillMultiScriptJoins(handle: Database.Database): void {
handle.exec(
`INSERT INTO beta_scripts (beta_id, script_id, script_version_id)
@@ -144,9 +143,11 @@ function backfillMultiScriptJoins(handle: Database.Database): void {
WHERE b.script_id IS NOT NULL
AND bs.server_deleted_at IS NULL
AND EXISTS (SELECT 1 FROM servers WHERE name = bs.server)
AND (SELECT COUNT(*) FROM beta_scripts x WHERE x.beta_id = b.id) = 1
AND EXISTS (SELECT 1 FROM beta_scripts x WHERE x.beta_id = b.id AND x.script_id = b.script_id)
AND NOT EXISTS (
SELECT 1 FROM beta_server_scripts x
WHERE x.beta_id = bs.beta_id AND x.server = bs.server AND x.script_id = b.script_id
WHERE x.beta_id = bs.beta_id AND x.server = bs.server
)`
);
handle.exec(