Allow deleting settled autoscaling policies

This commit is contained in:
2026-10-06 23:41:37 -04:00
parent 285279ee6d
commit 34648b34e0
7 changed files with 131 additions and 5 deletions
+18
View File
@@ -75,6 +75,24 @@ export function saveScaling(input: unknown, id?: string, revision?: number, toke
})();
}
export function deleteScaling(id: string, revision: number): void {
db().transaction(() => {
const policy = getScalingPolicy(id);
if (!policy) throw new ScalingError('Policy not found.', 404);
if (policy.revision !== revision) throw new ScalingError('Policy changed. Refresh before deleting.', 409);
// Keep admission evidence and ownership while a host command may still act.
if (db().prepare('SELECT 1 FROM autoscaling_decisions WHERE policy_id=? AND resolved=0').get(id)) {
throw new ScalingError('Pause this policy and settle its outstanding Provisioning work before deleting it.', 409);
}
revokePolicyRemovals(id);
db().prepare('DELETE FROM autoscaling_authorizations WHERE policy_id=?').run(id);
db().prepare('DELETE FROM autoscaling_members WHERE policy_id=?').run(id);
db().prepare('DELETE FROM autoscaling_samples WHERE policy_id=?').run(id);
db().prepare('DELETE FROM autoscaling_decisions WHERE policy_id=?').run(id);
db().prepare('DELETE FROM autoscaling_policies WHERE id=?').run(id);
})();
}
export function setScalingGlobalPause(paused: boolean): void {
db().transaction(() => {
db().prepare("INSERT INTO settings(key,value) VALUES('autoscaling_paused',?) ON CONFLICT(key) DO UPDATE SET value=excluded.value").run(paused ? '1' : '0');