Index beta evidence and foreign key child lookups

This commit is contained in:
2026-10-06 13:57:22 -04:00
parent 8e948c07d9
commit 27be1abf41
6 changed files with 77 additions and 0 deletions
+2
View File
@@ -10,6 +10,7 @@ import { backfillLeaderboard } from '../fleet/leaderboard-ingest.js';
import { initializeFleetSettings } from './fleet-settings.js';
import { migrateServerHistory } from './server-history.js';
import { migrateNativeInstances } from '../backends/schema.js';
import { installPerformanceIndexes } from './performance-indexes.js';
import { timeStatement } from './slow-statements.js';
let _db: Database.Database | null = null;
@@ -404,6 +405,7 @@ export function db(): Database.Database {
ON server_deployments(finished_at) WHERE server_deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_server_deployments_unsettled
ON server_deployments(id) WHERE state NOT IN ('done','warning','cancelled');`);
installPerformanceIndexes(handle);
installReportRevisions(handle);
} catch (err) {
handle.close();
+27
View File
@@ -0,0 +1,27 @@
import type Database from 'better-sqlite3';
/** Install after additive column and history migrations, on new and existing databases. */
export function installPerformanceIndexes(handle: Database.Database): void {
handle.exec(`
CREATE INDEX IF NOT EXISTS idx_staged_files_deployment_file ON staged_file_changes(deployment_file_id);
CREATE INDEX IF NOT EXISTS idx_beta_test_runs_beta_revision ON beta_test_runs(beta_id, revision);
CREATE INDEX IF NOT EXISTS idx_deployments_beta ON deployments(beta_id);
CREATE INDEX IF NOT EXISTS idx_deployments_script ON deployments(script_id);
CREATE INDEX IF NOT EXISTS idx_deployments_version ON deployments(script_version_id);
CREATE INDEX IF NOT EXISTS idx_deployments_prior ON deployments(prior_version_id);
CREATE INDEX IF NOT EXISTS idx_deployment_scripts_script ON deployment_scripts(script_id);
CREATE INDEX IF NOT EXISTS idx_deployment_scripts_version ON deployment_scripts(script_version_id);
CREATE INDEX IF NOT EXISTS idx_deployment_scripts_prior ON deployment_scripts(prior_version_id);
CREATE INDEX IF NOT EXISTS idx_server_scripts_version ON server_scripts(script_version_id);
CREATE INDEX IF NOT EXISTS idx_betas_version ON betas(script_version_id);
CREATE INDEX IF NOT EXISTS idx_beta_scripts_version ON beta_scripts(script_version_id);
CREATE INDEX IF NOT EXISTS idx_beta_servers_prior ON beta_servers(prior_version_id);
CREATE INDEX IF NOT EXISTS idx_beta_server_scripts_script ON beta_server_scripts(script_id);
CREATE INDEX IF NOT EXISTS idx_beta_server_scripts_prior ON beta_server_scripts(prior_version_id);
CREATE INDEX IF NOT EXISTS idx_beta_file_snapshots_server ON beta_file_snapshots(server);
CREATE INDEX IF NOT EXISTS idx_server_launch_previews_deployment ON server_launch_previews(deployment_id);
CREATE INDEX IF NOT EXISTS idx_server_collection_previews_collection ON server_collection_previews(collection_id);
CREATE INDEX IF NOT EXISTS idx_server_collection_removals_deployment ON server_collection_removals(deployment_id);
CREATE INDEX IF NOT EXISTS idx_server_creation_dependencies_removal ON server_creation_dependencies(removal_id);
`);
}