Fix keyed telemetry match attribution (Refs #144)
CI / checks (push) Successful in 5m26s

This commit is contained in:
2026-10-12 00:58:05 -04:00
parent 4ea291d305
commit 785cc4616b
24 changed files with 1115 additions and 112 deletions
+29
View File
@@ -0,0 +1,29 @@
import type Database from 'better-sqlite3';
/** Reporter identities and received sequences survive controller restarts with match history. */
export function migrateLeaderboardReports(handle: Database.Database): void {
const columns = new Set(
(handle.prepare('PRAGMA table_info(leaderboard_matches)').all() as { name: string }[]).map(
(column) => column.name
)
);
for (const [name, definition] of [
['reporter_match_key', 'TEXT'],
['last_seq', 'INTEGER NOT NULL DEFAULT 0'],
['report_count', 'INTEGER NOT NULL DEFAULT 0']
]) {
if (!columns.has(name))
handle.exec(`ALTER TABLE leaderboard_matches ADD COLUMN ${name} ${definition}`);
}
handle.exec(`
CREATE UNIQUE INDEX IF NOT EXISTS idx_leaderboard_reporter_match
ON leaderboard_matches(server, reporter_match_key)
WHERE reporter_match_key IS NOT NULL;
CREATE TABLE IF NOT EXISTS leaderboard_match_reports (
match_id INTEGER NOT NULL REFERENCES leaderboard_matches(id) ON DELETE CASCADE,
seq INTEGER NOT NULL CHECK (typeof(seq) = 'integer' AND seq > 0),
applied INTEGER NOT NULL CHECK (applied IN (0,1)),
PRIMARY KEY (match_id, seq)
);
`);
}
+6
View File
@@ -16,6 +16,7 @@ import { enableIncrementalVacuum, retentionClocks } from './retention-clocks.js'
import { migrateHostSchema } from '../hosts/schema.js';
import { migrateAuthSchema, migrateSuperViewerRole } from '../auth/schema.js';
import { migrateGameFileSchema } from '../game-files/schema.js';
import { migrateLeaderboardReports } from './leaderboard-reports.js';
import type { Migration } from './migration-runner.js';
// Append only: never renumber entries or change an applied migration to add an
@@ -97,6 +98,11 @@ export const migrations: readonly Migration[] = [
name: 'super viewer authentication role',
mode: 'foreign-keys-off',
run: migrateSuperViewerRole
},
{
version: 18,
name: 'durable leaderboard report identity and sequences',
run: migrateLeaderboardReports
}
];