fix: millisecond precision timestamps and correct history ordering #58
16
server/db.js
16
server/db.js
@@ -173,7 +173,8 @@ export function createInstance(data) {
|
|||||||
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
||||||
`).run(data);
|
`).run(data);
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, 'created', NULL, NULL)`
|
`INSERT INTO instance_history (vmid, field, old_value, new_value, changed_at)
|
||||||
|
VALUES (?, 'created', NULL, NULL, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||||
).run(data.vmid);
|
).run(data.vmid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,12 +185,13 @@ export function updateInstance(vmid, data) {
|
|||||||
name=@name, state=@state, stack=@stack, vmid=@newVmid,
|
name=@name, state=@state, stack=@stack, vmid=@newVmid,
|
||||||
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
|
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
|
||||||
tailscale=@tailscale, andromeda=@andromeda, tailscale_ip=@tailscale_ip,
|
tailscale=@tailscale, andromeda=@andromeda, tailscale_ip=@tailscale_ip,
|
||||||
hardware_acceleration=@hardware_acceleration, updated_at=datetime('now')
|
hardware_acceleration=@hardware_acceleration, updated_at=strftime('%Y-%m-%dT%H:%M:%f', 'now')
|
||||||
WHERE vmid=@vmid
|
WHERE vmid=@vmid
|
||||||
`).run({ ...data, newVmid: data.vmid, vmid });
|
`).run({ ...data, newVmid: data.vmid, vmid });
|
||||||
const newVmid = data.vmid;
|
const newVmid = data.vmid;
|
||||||
const insertEvt = db.prepare(
|
const insertEvt = db.prepare(
|
||||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, ?, ?, ?)`
|
`INSERT INTO instance_history (vmid, field, old_value, new_value, changed_at)
|
||||||
|
VALUES (?, ?, ?, ?, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||||
);
|
);
|
||||||
for (const field of HISTORY_FIELDS) {
|
for (const field of HISTORY_FIELDS) {
|
||||||
const oldVal = String(old[field] ?? '');
|
const oldVal = String(old[field] ?? '');
|
||||||
@@ -227,7 +229,7 @@ export function importInstances(rows, historyRows = []) {
|
|||||||
|
|
||||||
export function getInstanceHistory(vmid) {
|
export function getInstanceHistory(vmid) {
|
||||||
return db.prepare(
|
return db.prepare(
|
||||||
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at ASC, id ASC'
|
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at DESC, id DESC'
|
||||||
).all(vmid);
|
).all(vmid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,12 +311,14 @@ export function updateJob(id, { enabled, schedule, config }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createJobRun(jobId) {
|
export function createJobRun(jobId) {
|
||||||
return Number(db.prepare('INSERT INTO job_runs (job_id) VALUES (?)').run(jobId).lastInsertRowid);
|
return Number(db.prepare(
|
||||||
|
`INSERT INTO job_runs (job_id, started_at) VALUES (?, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||||
|
).run(jobId).lastInsertRowid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function completeJobRun(runId, status, result) {
|
export function completeJobRun(runId, status, result) {
|
||||||
db.prepare(`
|
db.prepare(`
|
||||||
UPDATE job_runs SET ended_at=datetime('now'), status=@status, result=@result WHERE id=@id
|
UPDATE job_runs SET ended_at=strftime('%Y-%m-%dT%H:%M:%f', 'now'), status=@status, result=@result WHERE id=@id
|
||||||
`).run({ id: runId, status, result });
|
`).run({ id: runId, status, result });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user