fix: clear instance history on delete and import
deleteInstance now removes history rows for that vmid before removing the instance. importInstances clears all history before replacing instances. Prevents stale history appearing when a vmid is reused. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -151,11 +151,13 @@ export function updateInstance(vmid, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteInstance(vmid) {
|
export function deleteInstance(vmid) {
|
||||||
return db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
db.prepare('DELETE FROM instance_history WHERE vmid = ?').run(vmid);
|
||||||
|
db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function importInstances(rows) {
|
export function importInstances(rows) {
|
||||||
db.exec('BEGIN');
|
db.exec('BEGIN');
|
||||||
|
db.exec('DELETE FROM instance_history');
|
||||||
db.exec('DELETE FROM instances');
|
db.exec('DELETE FROM instances');
|
||||||
const insert = db.prepare(`
|
const insert = db.prepare(`
|
||||||
INSERT INTO instances
|
INSERT INTO instances
|
||||||
|
|||||||
@@ -164,6 +164,19 @@ describe('deleteInstance', () => {
|
|||||||
expect(getInstance(1)).toBeNull();
|
expect(getInstance(1)).toBeNull();
|
||||||
expect(getInstance(2)).not.toBeNull();
|
expect(getInstance(2)).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clears history for the deleted instance', () => {
|
||||||
|
createInstance({ ...base, name: 'a', vmid: 1 });
|
||||||
|
deleteInstance(1);
|
||||||
|
expect(getInstanceHistory(1)).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not clear history for other instances', () => {
|
||||||
|
createInstance({ ...base, name: 'a', vmid: 1 });
|
||||||
|
createInstance({ ...base, name: 'b', vmid: 2 });
|
||||||
|
deleteInstance(1);
|
||||||
|
expect(getInstanceHistory(2).length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── importInstances ───────────────────────────────────────────────────────────
|
// ── importInstances ───────────────────────────────────────────────────────────
|
||||||
@@ -183,6 +196,12 @@ describe('importInstances', () => {
|
|||||||
importInstances([]);
|
importInstances([]);
|
||||||
expect(getInstances()).toEqual([]);
|
expect(getInstances()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clears history for all replaced instances', () => {
|
||||||
|
createInstance({ ...base, name: 'old', vmid: 1 });
|
||||||
|
importInstances([{ ...base, name: 'new', vmid: 2 }]);
|
||||||
|
expect(getInstanceHistory(1)).toHaveLength(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── instance history ─────────────────────────────────────────────────────────
|
// ── instance history ─────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user