feat(auto-update): per-stack auto-update enable/disable toggle (#771)

* feat(auto-update): add per-stack auto-update enable/disable toggle

Paid users (Skipper and Admiral) can now opt individual stacks out of
scheduled auto-updates from the stack context menu without disabling
the global feature.

- Add stack_auto_update_settings table (node_id, stack_name) with
  default enabled=true; four typed DatabaseService accessors with
  parameterized queries.
- Add GET /stacks/auto-update-settings, GET /stacks/:name/auto-update,
  and PUT /stacks/:name/auto-update (requirePaid + requireAdmin).
  PUT broadcasts state-invalidate with action auto-update-settings-changed
  so all open tabs refresh immediately.
- Stack DELETE clears the auto-update setting row alongside stack_update_status.
- autoUpdateRouter /execute skips disabled stacks before any registry
  call; skip is recorded in the results array. Manual Update actions
  are not affected.
- Add Auto-update: Enabled/Disabled toggle in the stack inspect group
  (paid tiers only, hidden for Community, consistent with Auto-Heal).
  Toggle uses optimistic update with revert-on-error toast.
- AutoUpdateReadinessView shows an Auto: Off pill and disables the
  Apply now button for stacks with auto-updates off. Detection still
  runs so the readiness card remains visible.
- Add 21 backend Vitest tests covering DB round-trips, endpoint auth
  and tier gates, execute skip for both wildcard and named targets.
  Add 3 frontend hook tests for toggle visibility and callback behavior.

* docs(auto-update): document per-stack auto-update control

Add a Per-stack control section to the auto-update readiness page
explaining how to disable and re-enable auto-updates for individual
stacks, what disabling means (scheduled apply skipped; detection still
runs; manual update unaffected), and a troubleshooting entry for
scheduled runs not applying to a specific stack.
This commit is contained in:
Anso
2026-04-25 10:50:21 -04:00
committed by GitHub
parent 58df1a50b3
commit af9cb0aa63
10 changed files with 501 additions and 10 deletions
+42
View File
@@ -559,6 +559,14 @@ export class DatabaseService {
PRIMARY KEY (node_id, stack_name)
);
CREATE TABLE IF NOT EXISTS stack_auto_update_settings (
node_id INTEGER NOT NULL DEFAULT 0,
stack_name TEXT NOT NULL,
auto_update_enabled INTEGER NOT NULL DEFAULT 1,
updated_at INTEGER NOT NULL,
PRIMARY KEY (node_id, stack_name)
);
CREATE TABLE IF NOT EXISTS nodes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
@@ -1722,6 +1730,40 @@ export class DatabaseService {
this.db.prepare('DELETE FROM stack_update_status WHERE node_id = ? AND stack_name = ?').run(nodeId, stackName);
}
// --- Stack Auto-Update Settings ---
public getStackAutoUpdateEnabled(nodeId: number, stackName: string): boolean {
const row = this.db.prepare(
'SELECT auto_update_enabled FROM stack_auto_update_settings WHERE node_id = ? AND stack_name = ?'
).get(nodeId, stackName) as { auto_update_enabled: number } | undefined;
return row === undefined ? true : row.auto_update_enabled === 1;
}
// Returns only stacks with an explicit row. Missing keys default to true
// (auto-update enabled); callers must not treat absence as false.
public getStackAutoUpdateSettingsForNode(nodeId: number): Record<string, boolean> {
const rows = this.db.prepare(
'SELECT stack_name, auto_update_enabled FROM stack_auto_update_settings WHERE node_id = ?'
).all(nodeId) as Array<{ stack_name: string; auto_update_enabled: number }>;
const result: Record<string, boolean> = {};
for (const row of rows) {
result[row.stack_name] = row.auto_update_enabled === 1;
}
return result;
}
public upsertStackAutoUpdateEnabled(nodeId: number, stackName: string, enabled: boolean): void {
this.db.prepare(
`INSERT INTO stack_auto_update_settings (node_id, stack_name, auto_update_enabled, updated_at)
VALUES (?, ?, ?, ?)
ON CONFLICT(node_id, stack_name) DO UPDATE SET auto_update_enabled = excluded.auto_update_enabled, updated_at = excluded.updated_at`
).run(nodeId, stackName, enabled ? 1 : 0, Date.now());
}
public clearStackAutoUpdateSetting(nodeId: number, stackName: string): void {
this.db.prepare('DELETE FROM stack_auto_update_settings WHERE node_id = ? AND stack_name = ?').run(nodeId, stackName);
}
public getNodeUpdateSummary(): Array<{ node_id: number; stacks_with_updates: number }> {
return this.db.prepare(
'SELECT node_id, SUM(has_update) as stacks_with_updates FROM stack_update_status WHERE has_update = 1 GROUP BY node_id'