Separate campaigns from server deployment lifecycle tracking

This commit is contained in:
2026-09-17 16:42:37 -04:00
parent 6c6e63fa80
commit 6f83700161
20 changed files with 1434 additions and 1108 deletions
+30
View File
@@ -0,0 +1,30 @@
import { randomUUID } from 'node:crypto';
import { db } from '../db/index.js';
export function beginDeployment(server: string, action: 'create' | 'destroy', triggeredBy = 'ui'): string {
const id = randomUUID();
db().prepare(`INSERT INTO server_deployments (id, server, action, state, stage, started_at, triggered_by)
VALUES (?, ?, ?, 'running', 'Starting', ?, ?)`).run(id, server, action, new Date().toISOString(), triggeredBy);
return id;
}
export function deploymentStage(id: string, stage: string): void {
db().prepare('UPDATE server_deployments SET stage = ? WHERE id = ?').run(stage, id);
}
export function finishDeployment(id: string, result: { ok: boolean; message?: string; warnings?: string[] }): void {
const state = !result.ok ? 'failed' : result.warnings?.length ? 'warning' : 'done';
db().prepare(`UPDATE server_deployments SET state = ?, finished_at = ?, error = ?, warnings = ? WHERE id = ?`)
.run(state, new Date().toISOString(), result.message ?? null, JSON.stringify(result.warnings ?? []), id);
}
export function listDeployments() {
return db().prepare(`SELECT d.*, EXISTS(SELECT 1 FROM servers s WHERE s.name = d.server) AS server_exists
FROM server_deployments d ORDER BY started_at DESC, rowid DESC`).all();
}
export function interruptDeployments(): void {
db().prepare(`UPDATE server_deployments SET state = 'interrupted', finished_at = ?,
error = 'The application restarted before this operation finished. Check the server before retrying.'
WHERE state = 'running'`).run(new Date().toISOString());
}