47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
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, snapshot_pending,
|
|
LENGTH(content_before) AS size_before,
|
|
LENGTH(content_after) AS size_after,
|
|
COALESCE((SELECT state FROM staged_file_changes WHERE deployment_file_id = deployment_files.id), 'applied') AS apply_state
|
|
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);
|
|
|
|
const events = db().prepare('SELECT id, created_at, message FROM campaign_events WHERE deployment_id = ? ORDER BY id').all(params.id);
|
|
const watchdog = db().prepare('SELECT incident_id FROM watchdog_actions WHERE campaign_id = ? LIMIT 1').get(params.id) as { incident_id: string } | undefined;
|
|
const fileContentsExpired = !!db().prepare("SELECT 1 FROM retention_expirations WHERE category='file-content' AND record_id=?").get(params.id);
|
|
return json({ fileContentsExpired, deployment: dep, servers, files, scripts, events, watchdogIncidentId: watchdog?.incident_id ?? null });
|
|
}
|