Allow deleting settled autoscaling policies
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -60,7 +60,10 @@ function warningMessages(raw: string): string[] {
|
||||
|
||||
function sourceDetails(source: Omit<ProvisioningSource, 'label' | 'href'>): ProvisioningSource {
|
||||
const id = source.source_id;
|
||||
if (source.kind === 'autoscaling') return { ...source, label: 'Autoscaling policy', href: `/autoscaling#${encodeURIComponent(id)}` };
|
||||
if (source.kind === 'autoscaling') {
|
||||
const exists = !!db().prepare('SELECT 1 FROM autoscaling_policies WHERE id=?').get(id);
|
||||
return { ...source, label: exists ? 'Autoscaling policy' : 'Deleted autoscaling policy', href: exists ? `/autoscaling#${encodeURIComponent(id)}` : null };
|
||||
}
|
||||
if (source.kind === 'campaign') {
|
||||
const row = db().prepare(`SELECT d.action, d.beta_id, s.name FROM deployments d
|
||||
LEFT JOIN scripts s ON s.id=COALESCE(d.script_id, (SELECT script_id FROM deployment_scripts WHERE deployment_id=d.id ORDER BY script_id LIMIT 1))
|
||||
|
||||
Reference in New Issue
Block a user