feat: include history in export/import backup
Export now returns version 2 with a history array alongside instances. Import accepts the history array and restores all audit events. v1 backups without a history key still import cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
12
server/db.js
12
server/db.js
@@ -155,7 +155,7 @@ export function deleteInstance(vmid) {
|
||||
db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
||||
}
|
||||
|
||||
export function importInstances(rows) {
|
||||
export function importInstances(rows, historyRows = []) {
|
||||
db.exec('BEGIN');
|
||||
db.exec('DELETE FROM instance_history');
|
||||
db.exec('DELETE FROM instances');
|
||||
@@ -168,6 +168,12 @@ export function importInstances(rows) {
|
||||
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
||||
`);
|
||||
for (const row of rows) insert.run(row);
|
||||
if (historyRows.length) {
|
||||
const insertHist = db.prepare(
|
||||
`INSERT INTO instance_history (vmid, field, old_value, new_value, changed_at) VALUES (?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const h of historyRows) insertHist.run(h.vmid, h.field, h.old_value ?? null, h.new_value ?? null, h.changed_at);
|
||||
}
|
||||
db.exec('COMMIT');
|
||||
}
|
||||
|
||||
@@ -177,6 +183,10 @@ export function getInstanceHistory(vmid) {
|
||||
).all(vmid);
|
||||
}
|
||||
|
||||
export function getAllHistory() {
|
||||
return db.prepare('SELECT * FROM instance_history ORDER BY vmid, changed_at').all();
|
||||
}
|
||||
|
||||
// ── Test helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
export function _resetForTest() {
|
||||
|
||||
Reference in New Issue
Block a user