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 () { +};