Add db migration to ensure done checklist items have an owner and timestamp
This commit is contained in:
@@ -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 () {
|
||||
};
|
||||
Reference in New Issue
Block a user