Index beta evidence and foreign key child lookups
This commit is contained in:
@@ -41,6 +41,7 @@ export function migrateNativeInstances(handle: Database.Database): void {
|
||||
creation_id TEXT PRIMARY KEY REFERENCES server_deployments(id),
|
||||
cleanup_id TEXT NOT NULL UNIQUE REFERENCES server_deployments(id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_ec_host_migrations_instance ON ec_host_migrations(instance_id);
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
`);
|
||||
}
|
||||
@@ -48,6 +48,7 @@ export function ensureGameFileSchema(handle: Database.Database): void {
|
||||
FROM game_file_versions v,json_each(v.manifest) f;
|
||||
CREATE TRIGGER IF NOT EXISTS game_file_versions_immutable BEFORE UPDATE ON game_file_versions
|
||||
WHEN OLD.state = 'ready' BEGIN SELECT RAISE(ABORT, 'Published game-file versions are immutable'); END;
|
||||
CREATE INDEX IF NOT EXISTS idx_host_library_caches_version ON host_library_caches(version_id);
|
||||
`);
|
||||
const versionColumns = handle.prepare('PRAGMA table_info(game_file_versions)').all() as { name: string }[];
|
||||
if (!versionColumns.some(column => column.name === 'last_activity_at')) handle.exec('ALTER TABLE game_file_versions ADD COLUMN last_activity_at TEXT');
|
||||
|
||||
@@ -89,6 +89,8 @@ export function ensureHostSchema(handle: Database.Database): void {
|
||||
CHECK(stage IN ('queued','running','cleaned','failed','completed')),
|
||||
requested_at TEXT NOT NULL, updated_at TEXT NOT NULL, cleaned_at TEXT, error TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_ec_host_credentials_host ON ec_host_credentials(host_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ec_host_enrollments_host ON ec_host_enrollments(host_id);
|
||||
`);
|
||||
const columns = handle.prepare('PRAGMA table_info(ec_host_operations)').all() as { name: string }[];
|
||||
if (!columns.some(column => column.name === 'history_expired_at')) handle.exec('ALTER TABLE ec_host_operations ADD COLUMN history_expired_at TEXT');
|
||||
|
||||
Reference in New Issue
Block a user