Separate campaigns from server deployment lifecycle tracking
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
export async function GET({ url }: { url: URL }) {
|
||||
const activeOnly = url.searchParams.get('active') === 'true';
|
||||
|
||||
const deployments = db()
|
||||
.prepare(
|
||||
`SELECT d.id, d.action, d.started_at, d.finished_at, d.triggered_by,
|
||||
d.script_id, d.script_version_id, d.prior_version_id, d.beta_id, d.rolled_back_by,
|
||||
s.name AS script_name, sv.version AS script_version,
|
||||
pv.version AS prior_version
|
||||
FROM deployments d
|
||||
LEFT JOIN scripts s ON s.id = d.script_id
|
||||
LEFT JOIN script_versions sv ON sv.id = d.script_version_id
|
||||
LEFT JOIN script_versions pv ON pv.id = d.prior_version_id
|
||||
ORDER BY d.started_at DESC
|
||||
LIMIT 500`
|
||||
)
|
||||
.all() as Array<{
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
script_id: number | null;
|
||||
script_version_id: number | null;
|
||||
prior_version_id: number | null;
|
||||
beta_id: number | null;
|
||||
rolled_back_by: string | null;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
}>;
|
||||
|
||||
const serversByDep = db()
|
||||
.prepare(
|
||||
`SELECT deployment_id, server, files_changed, restart_state, players, checked_at, restarted_at, attempts, error
|
||||
FROM deployment_servers`
|
||||
)
|
||||
.all() as Array<{
|
||||
deployment_id: string;
|
||||
server: string;
|
||||
files_changed: number;
|
||||
restart_state: string;
|
||||
players: number | null;
|
||||
checked_at: string | null;
|
||||
restarted_at: string | null;
|
||||
attempts: number;
|
||||
error: string | null;
|
||||
}>;
|
||||
|
||||
const grouped = new Map<string, typeof serversByDep>();
|
||||
for (const s of serversByDep) {
|
||||
const arr = grouped.get(s.deployment_id) ?? [];
|
||||
arr.push(s);
|
||||
grouped.set(s.deployment_id, arr);
|
||||
}
|
||||
|
||||
const scriptRows = db()
|
||||
.prepare(
|
||||
`SELECT ds.deployment_id, ds.script_id, s.name AS script_name,
|
||||
sv.version AS script_version, pv.version AS prior_version
|
||||
FROM deployment_scripts ds
|
||||
LEFT JOIN scripts s ON s.id = ds.script_id
|
||||
LEFT JOIN script_versions sv ON sv.id = ds.script_version_id
|
||||
LEFT JOIN script_versions pv ON pv.id = ds.prior_version_id`
|
||||
)
|
||||
.all() as Array<{
|
||||
deployment_id: string;
|
||||
script_id: number;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
}>;
|
||||
const scriptsByDep = new Map<string, typeof scriptRows>();
|
||||
for (const s of scriptRows) {
|
||||
const arr = scriptsByDep.get(s.deployment_id) ?? [];
|
||||
arr.push(s);
|
||||
scriptsByDep.set(s.deployment_id, arr);
|
||||
}
|
||||
|
||||
const rows = deployments
|
||||
.map((d) => ({
|
||||
...d,
|
||||
servers: grouped.get(d.id) ?? [],
|
||||
scripts: scriptsByDep.get(d.id) ?? []
|
||||
}))
|
||||
.filter((d) => (activeOnly ? d.servers.some((s) => s.restart_state === 'pending' || s.restart_state === 'failed') : true));
|
||||
|
||||
return json({ deployments: rows });
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
export async function GET({ params }: { params: { id: string } }) {
|
||||
const dep = db()
|
||||
.prepare('SELECT * FROM deployments WHERE id = ?')
|
||||
.get(params.id) as Record<string, unknown> | undefined;
|
||||
if (!dep) throw error(404, 'deployment not found');
|
||||
|
||||
const servers = db()
|
||||
.prepare('SELECT * FROM deployment_servers WHERE deployment_id = ? ORDER BY server')
|
||||
.all(params.id);
|
||||
|
||||
// Don't ship blobs in the summary — the client asks for a single file when
|
||||
// it opens the diff viewer.
|
||||
const files = db()
|
||||
.prepare(
|
||||
`SELECT id, server, verb, rel_path, sha256_before, sha256_after,
|
||||
LENGTH(content_before) AS size_before,
|
||||
LENGTH(content_after) AS size_after
|
||||
FROM deployment_files
|
||||
WHERE deployment_id = ?
|
||||
ORDER BY server, rel_path`
|
||||
)
|
||||
.all(params.id);
|
||||
|
||||
const scripts = db()
|
||||
.prepare(
|
||||
`SELECT ds.script_id, s.name AS script_name, s.target_rel_path,
|
||||
ds.script_version_id, sv.version AS script_version,
|
||||
ds.prior_version_id, pv.version AS prior_version
|
||||
FROM deployment_scripts ds
|
||||
LEFT JOIN scripts s ON s.id = ds.script_id
|
||||
LEFT JOIN script_versions sv ON sv.id = ds.script_version_id
|
||||
LEFT JOIN script_versions pv ON pv.id = ds.prior_version_id
|
||||
WHERE ds.deployment_id = ?
|
||||
ORDER BY ds.script_id`
|
||||
)
|
||||
.all(params.id);
|
||||
|
||||
return json({ deployment: dep, servers, files, scripts });
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
// Streams a single deployment_files row's before/after blobs as UTF-8 text
|
||||
// so the DiffViewer can render a unified diff without a second query.
|
||||
|
||||
export async function GET({ params }: { params: { id: string; fileId: string } }) {
|
||||
const row = db()
|
||||
.prepare(
|
||||
`SELECT verb, rel_path, sha256_before, sha256_after, content_before, content_after
|
||||
FROM deployment_files
|
||||
WHERE deployment_id = ? AND id = ?`
|
||||
)
|
||||
.get(params.id, Number(params.fileId)) as
|
||||
| {
|
||||
verb: string;
|
||||
rel_path: string;
|
||||
sha256_before: string | null;
|
||||
sha256_after: string | null;
|
||||
content_before: Buffer | null;
|
||||
content_after: Buffer | null;
|
||||
}
|
||||
| undefined;
|
||||
if (!row) throw error(404, 'file not found');
|
||||
|
||||
return json({
|
||||
verb: row.verb,
|
||||
relPath: row.rel_path,
|
||||
sha256Before: row.sha256_before,
|
||||
sha256After: row.sha256_after,
|
||||
before: row.content_before ? row.content_before.toString('utf8') : null,
|
||||
after: row.content_after ? row.content_after.toString('utf8') : null
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { rollbackPromoteDeployment, RollbackError } from '$lib/server/fleet/rollback.js';
|
||||
|
||||
export async function POST({ params }: { params: { id: string } }) {
|
||||
try {
|
||||
const result = await rollbackPromoteDeployment(params.id);
|
||||
return json({ ok: true, result });
|
||||
} catch (err) {
|
||||
if (err instanceof RollbackError) {
|
||||
return json({ ok: false, error: err.message, kind: err.kind }, { status: 409 });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +1,3 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
export async function GET({ url }: { url: URL }) {
|
||||
const activeOnly = url.searchParams.get('active') === 'true';
|
||||
|
||||
const deployments = db()
|
||||
.prepare(
|
||||
`SELECT d.id, d.action, d.started_at, d.finished_at, d.triggered_by,
|
||||
d.script_id, d.script_version_id, d.prior_version_id, d.beta_id, d.rolled_back_by,
|
||||
s.name AS script_name, sv.version AS script_version,
|
||||
pv.version AS prior_version
|
||||
FROM deployments d
|
||||
LEFT JOIN scripts s ON s.id = d.script_id
|
||||
LEFT JOIN script_versions sv ON sv.id = d.script_version_id
|
||||
LEFT JOIN script_versions pv ON pv.id = d.prior_version_id
|
||||
ORDER BY d.started_at DESC
|
||||
LIMIT 500`
|
||||
)
|
||||
.all() as Array<{
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
script_id: number | null;
|
||||
script_version_id: number | null;
|
||||
prior_version_id: number | null;
|
||||
beta_id: number | null;
|
||||
rolled_back_by: string | null;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
}>;
|
||||
|
||||
const serversByDep = db()
|
||||
.prepare(
|
||||
`SELECT deployment_id, server, files_changed, restart_state, players, checked_at, restarted_at, attempts, error
|
||||
FROM deployment_servers`
|
||||
)
|
||||
.all() as Array<{
|
||||
deployment_id: string;
|
||||
server: string;
|
||||
files_changed: number;
|
||||
restart_state: string;
|
||||
players: number | null;
|
||||
checked_at: string | null;
|
||||
restarted_at: string | null;
|
||||
attempts: number;
|
||||
error: string | null;
|
||||
}>;
|
||||
|
||||
const grouped = new Map<string, typeof serversByDep>();
|
||||
for (const s of serversByDep) {
|
||||
const arr = grouped.get(s.deployment_id) ?? [];
|
||||
arr.push(s);
|
||||
grouped.set(s.deployment_id, arr);
|
||||
}
|
||||
|
||||
const scriptRows = db()
|
||||
.prepare(
|
||||
`SELECT ds.deployment_id, ds.script_id, s.name AS script_name,
|
||||
sv.version AS script_version, pv.version AS prior_version
|
||||
FROM deployment_scripts ds
|
||||
LEFT JOIN scripts s ON s.id = ds.script_id
|
||||
LEFT JOIN script_versions sv ON sv.id = ds.script_version_id
|
||||
LEFT JOIN script_versions pv ON pv.id = ds.prior_version_id`
|
||||
)
|
||||
.all() as Array<{
|
||||
deployment_id: string;
|
||||
script_id: number;
|
||||
script_name: string | null;
|
||||
script_version: number | null;
|
||||
prior_version: number | null;
|
||||
}>;
|
||||
const scriptsByDep = new Map<string, typeof scriptRows>();
|
||||
for (const s of scriptRows) {
|
||||
const arr = scriptsByDep.get(s.deployment_id) ?? [];
|
||||
arr.push(s);
|
||||
scriptsByDep.set(s.deployment_id, arr);
|
||||
}
|
||||
|
||||
const rows = deployments
|
||||
.map((d) => ({
|
||||
...d,
|
||||
servers: grouped.get(d.id) ?? [],
|
||||
scripts: scriptsByDep.get(d.id) ?? []
|
||||
}))
|
||||
.filter((d) => (activeOnly ? d.servers.some((s) => s.restart_state === 'pending' || s.restart_state === 'failed') : true));
|
||||
|
||||
return json({ deployments: rows });
|
||||
}
|
||||
import { listDeployments } from '$lib/server/fleet/deployments.js';
|
||||
export function GET() { return json({ deployments: listDeployments() }); }
|
||||
|
||||
Reference in New Issue
Block a user