migration 026 backup_runs; POST ingest (owner) from offsite-backup.sh, GET for the Sacred Valley card showing last run, per-guest sizes, Farm free, schedule. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
22 lines
764 B
JavaScript
22 lines
764 B
JavaScript
import { pool } from '../pool.js';
|
|
|
|
export async function record({ ok = true, total_bytes = null, won_free_bytes = null,
|
|
guests = null, duration_sec = null }) {
|
|
const { rows: [r] } = await pool.query(
|
|
`INSERT INTO backup_runs (ok, total_bytes, won_free_bytes, guests, duration_sec)
|
|
VALUES ($1,$2,$3,$4,$5) RETURNING *`,
|
|
[ok, total_bytes, won_free_bytes, guests ? JSON.stringify(guests) : null, duration_sec]);
|
|
return r;
|
|
}
|
|
|
|
export async function latest() {
|
|
const { rows: [r] } = await pool.query(
|
|
`SELECT * FROM backup_runs ORDER BY id DESC LIMIT 1`);
|
|
return r || null;
|
|
}
|
|
|
|
export async function count() {
|
|
const { rows: [r] } = await pool.query(`SELECT count(*)::int AS n FROM backup_runs`);
|
|
return r.n;
|
|
}
|