Add autoscaling outcomes to Metrics (Refs #140)
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
/** Provisioning outcomes remain report inputs even after the policy is removed. */
|
||||
export function installMetricsProvisioningRevisions(handle: Database.Database) {
|
||||
for (const table of ['server_deployments', 'provisioning_sources'])
|
||||
for (const action of ['INSERT', 'UPDATE', 'DELETE']) {
|
||||
const versions =
|
||||
action === 'INSERT' ? ['NEW'] : action === 'DELETE' ? ['OLD'] : ['OLD', 'NEW'];
|
||||
const fields = ['server', 'action', 'state', 'started_at', 'finished_at'];
|
||||
const condition =
|
||||
table === 'provisioning_sources'
|
||||
? versions.map((row) => `${row}.kind='autoscaling'`).join(' OR ')
|
||||
: `EXISTS (SELECT 1 FROM provisioning_sources WHERE operation_id=${action === 'DELETE' ? 'OLD' : 'NEW'}.id AND kind='autoscaling')${
|
||||
action === 'UPDATE'
|
||||
? ` AND (${fields.map((field) => `OLD.${field} IS NOT NEW.${field}`).join(' OR ')})`
|
||||
: ''
|
||||
}`;
|
||||
handle.exec(`CREATE TRIGGER IF NOT EXISTS report_metrics_${table}_${action}
|
||||
AFTER ${action} ON ${table} WHEN ${condition}
|
||||
BEGIN UPDATE report_revisions SET revision=revision+1 WHERE topic='metrics'; END;`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Match demand includes active and interrupted matches, independent of leaderboard eligibility. */
|
||||
export function installMetricsMatchRevisions(handle: Database.Database) {
|
||||
for (const table of ['leaderboard_matches', 'leaderboard_match_players'])
|
||||
|
||||
Reference in New Issue
Block a user