feat: include job config and run history in export/import backup
Export bumped to version 3, now includes jobs (with raw unmasked config) and job_runs arrays. Import restores them when present and restarts the scheduler. Payloads without a jobs key leave jobs untouched, keeping v1/v2 backups fully compatible. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
27
server/db.js
27
server/db.js
@@ -235,6 +235,33 @@ export function getAllHistory() {
|
||||
return db.prepare('SELECT * FROM instance_history ORDER BY vmid, changed_at').all();
|
||||
}
|
||||
|
||||
export function getAllJobs() {
|
||||
return db.prepare('SELECT id, key, name, description, enabled, schedule, config FROM jobs ORDER BY id').all();
|
||||
}
|
||||
|
||||
export function getAllJobRuns() {
|
||||
return db.prepare('SELECT * FROM job_runs ORDER BY job_id, id').all();
|
||||
}
|
||||
|
||||
export function importJobs(jobRows, jobRunRows = []) {
|
||||
db.exec('BEGIN');
|
||||
db.exec('DELETE FROM job_runs');
|
||||
db.exec('DELETE FROM jobs');
|
||||
const insertJob = db.prepare(`
|
||||
INSERT INTO jobs (id, key, name, description, enabled, schedule, config)
|
||||
VALUES (@id, @key, @name, @description, @enabled, @schedule, @config)
|
||||
`);
|
||||
for (const j of jobRows) insertJob.run(j);
|
||||
if (jobRunRows.length) {
|
||||
const insertRun = db.prepare(`
|
||||
INSERT INTO job_runs (id, job_id, started_at, ended_at, status, result)
|
||||
VALUES (@id, @job_id, @started_at, @ended_at, @status, @result)
|
||||
`);
|
||||
for (const r of jobRunRows) insertRun.run(r);
|
||||
}
|
||||
db.exec('COMMIT');
|
||||
}
|
||||
|
||||
export function getConfig(key, defaultVal = '') {
|
||||
const row = db.prepare('SELECT value FROM config WHERE key = ?').get(key);
|
||||
return row ? row.value : defaultVal;
|
||||
|
||||
Reference in New Issue
Block a user