Files
electric-cherry/src/lib/server/db/migrations.ts
T

92 lines
3.6 KiB
TypeScript

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 {
installMetricsMatchRevisions,
installMetricsPolicyRevisions,
installMetricsProvisioningRevisions,
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
},
{
version: 13,
name: 'metrics policy report revisions',
run: installMetricsPolicyRevisions
},
{
version: 14,
name: 'metrics match report revisions',
run: installMetricsMatchRevisions
},
{
version: 15,
name: 'metrics provisioning report revisions',
run: installMetricsProvisioningRevisions
}
];
export const databaseVersion = migrations.length;