Use ordered SQLite migrations (Refs #75)
CI / checks (push) Successful in 5m6s

This commit is contained in:
2026-10-10 00:01:18 -04:00
parent a0663e43b8
commit 8d1bb69591
56 changed files with 1085 additions and 736 deletions
+71
View File
@@ -0,0 +1,71 @@
import { migrateLegacySchema, installLifecycleIndexes } from './legacy.js';
import { migrateNativeInstances } from '../backends/schema.js';
import { migrateServerKeys } from './server-keys.js';
import { ensureAutoscalingSchema } from '../autoscaling/schema.js';
import { ensureRebalancingSchema } from '../rebalancing/schema.js';
import { migrateFileBlobs } from './file-blobs.js';
import { installPerformanceIndexes } from './performance-indexes.js';
import { installReportRevisions } from '../reports/revisions.js';
import { enableIncrementalVacuum, retentionClocks } from './retention-clocks.js';
import { migrateHostSchema } from '../hosts/schema.js';
import { migrateAuthSchema } from '../auth/schema.js';
import { migrateGameFileSchema } from '../game-files/schema.js';
import type { Migration } from './migration-runner.js';
// Append only: never renumber entries or change an applied migration to add an
// upgrade. These initial steps bridge every historical, unversioned database;
// their old sentinels are compatibility inputs, not the migration ledger.
export const migrations: readonly Migration[] = [
{
version: 1,
name: 'legacy controller schema and backfills',
mode: 'foreign-keys-off',
run: migrateLegacySchema
},
{
version: 2,
name: 'native instances and file plans',
mode: 'foreign-keys-off',
run: migrateNativeInstances
},
{ version: 3, name: 'per-game server key pools', run: migrateServerKeys },
{ version: 4, name: 'autoscaling', run: ensureAutoscalingSchema },
{ version: 5, name: 'rebalancing', run: ensureRebalancingSchema },
// Native file plans are stripped before artifact bodies are moved to blobs.
{ version: 6, name: 'shared file blobs', run: migrateFileBlobs },
{
version: 7,
name: 'query indexes and report revisions',
run: (handle) => {
installLifecycleIndexes(handle);
installPerformanceIndexes(handle);
installReportRevisions(handle);
}
},
{
version: 8,
name: 'retention clocks and indexes',
run: (handle) =>
retentionClocks(handle, {
deployments: ['started_at', 'finished_at'],
server_deployments: ['started_at', 'finished_at'],
maintenance_jobs: ['requested_at', 'finished_at'],
watchdog_incidents: ['first_seen_at', 'finished_at'],
leaderboard_matches: ['started_at', 'last_received_at', 'ended_at'],
betas: ['opened_at', 'closed_at'],
script_versions: ['uploaded_at'],
retention_controls: ['resolved_at']
})
},
{ version: 9, name: 'hosts and saved command files', run: migrateHostSchema },
{ version: 10, name: 'authentication', run: migrateAuthSchema },
{ version: 11, name: 'game-file libraries', run: migrateGameFileSchema },
{
version: 12,
name: 'incremental vacuum page map',
mode: 'autocommit',
run: enableIncrementalVacuum
}
];
export const databaseVersion = migrations.length;