From d04afc26e7a1bca6f8a19b1d408dfaf76968ba85 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Sun, 1 Feb 2026 13:20:52 +0100 Subject: [PATCH] Add db migration to ensure done checklist items have an owner and timestamp --- ...120606-apps-ensure-checklist-properties.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 migrations/20260201120606-apps-ensure-checklist-properties.js diff --git a/migrations/20260201120606-apps-ensure-checklist-properties.js b/migrations/20260201120606-apps-ensure-checklist-properties.js new file mode 100644 index 000000000..c6a493ba7 --- /dev/null +++ b/migrations/20260201120606-apps-ensure-checklist-properties.js @@ -0,0 +1,24 @@ +'use strict'; + +exports.up = async function (db) { + const owner = await db.runSql('SELECT username FROM users WHERE role="owner" LIMIT 1'); + const ownerUsername = owner[0].username; + + const apps = await db.runSql('SELECT * FROM apps'); + for (const app of apps) { + if (!app.checklistJson) continue; + + const checklist = JSON.parse(app.checklistJson); + for (const key in checklist) { + if (!checklist[key].acknowledged) continue; + + if (!checklist[key].changedAt) checklist[key].changedAt = Date.now(); + if (!checklist[key].changedBy) checklist[key].changedBy = ownerUsername; + } + + await db.runSql('UPDATE apps SET checklistJson=? WHERE id=?', [ JSON.stringify(checklist), app.id ]); + } +}; + +exports.down = async function () { +};