Make metrics reflect autoscaling policies (Refs #137)
CI / checks (push) Successful in 4m49s
CI / checks (push) Successful in 4m49s
This commit is contained in:
@@ -1,5 +1,21 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
/** Current policy settings are inputs to historical metrics advice. */
|
||||
export function installMetricsPolicyRevisions(handle: Database.Database) {
|
||||
for (const table of ['autoscaling_policies', 'settings'])
|
||||
for (const action of ['INSERT', 'UPDATE', 'DELETE']) {
|
||||
const versions =
|
||||
action === 'INSERT' ? ['NEW'] : action === 'DELETE' ? ['OLD'] : ['OLD', 'NEW'];
|
||||
const condition =
|
||||
table === 'settings'
|
||||
? `WHEN ${versions.map((row) => `${row}.key='autoscaling_paused'`).join(' OR ')}`
|
||||
: '';
|
||||
handle.exec(`CREATE TRIGGER IF NOT EXISTS report_metrics_${table}_${action}
|
||||
AFTER ${action} ON ${table} ${condition}
|
||||
BEGIN UPDATE report_revisions SET revision=revision+1 WHERE topic='metrics'; END;`);
|
||||
}
|
||||
}
|
||||
|
||||
export function installReportRevisions(handle: Database.Database) {
|
||||
handle.exec(`CREATE TABLE IF NOT EXISTS report_revisions (topic TEXT PRIMARY KEY, revision INTEGER NOT NULL DEFAULT 0);
|
||||
INSERT OR IGNORE INTO report_revisions(topic) VALUES ('metrics'), ('leaderboard');`);
|
||||
|
||||
Reference in New Issue
Block a user