diff --git a/migrations/20210430230901-apps-alter-ts-update.js b/migrations/20210430230901-apps-alter-ts-update.js new file mode 100644 index 000000000..a1d537ce9 --- /dev/null +++ b/migrations/20210430230901-apps-alter-ts-update.js @@ -0,0 +1,15 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE apps MODIFY ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP', [], function (error) { + if (error) console.error(error); + callback(error); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE apps MODIFY ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', [], function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/src/appdb.js b/src/appdb.js index 7736c915f..0ca9057fb 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -367,6 +367,9 @@ function clear(callback) { } function update(id, app, callback) { + // ts is useful as a versioning mechanism (for example, icon changed). update the timestamp explicity in code instead of db. + // this way health and healthTime can be updated without changing ts + app.ts = new Date(); updateWithConstraints(id, app, '', callback); } @@ -457,7 +460,7 @@ function updateWithConstraints(id, app, constraints, callback) { function setHealth(appId, health, healthTime, callback) { assert.strictEqual(typeof appId, 'string'); assert.strictEqual(typeof health, 'string'); - assert(util.isDate(healthTime)); + assert(util.types.isDate(healthTime)); assert.strictEqual(typeof callback, 'function'); var values = { health, healthTime };