diff --git a/migrations/20180627010633-apps-add-ts.js b/migrations/20180627010633-apps-add-ts.js new file mode 100644 index 000000000..0271247f1 --- /dev/null +++ b/migrations/20180627010633-apps-add-ts.js @@ -0,0 +1,15 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE apps ADD COLUMN ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', function (error) { + if (error) console.error(error); + callback(error); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE apps DROP COLUMN ts ', function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 0c91f9cdf..bba875ad1 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -71,8 +71,9 @@ CREATE TABLE IF NOT EXISTS apps( domain VARCHAR(128) NOT NULL, dnsRecordId VARCHAR(512), // tracks any id that we got back to track dns updates accessRestrictionJson TEXT, // { users: [ ], groups: [ ] } - creationTime TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP, - updateTime TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP, + creationTime TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP, // when the app was installed + updateTime TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP, // when the last app update was done + ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, // when this db record was updated (useful for UI caching) memoryLimit BIGINT DEFAULT 0, xFrameOptions VARCHAR(512), sso BOOLEAN DEFAULT 1, // whether user chose to enable SSO diff --git a/src/appdb.js b/src/appdb.js index b986dc74f..2773f822f 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -62,7 +62,7 @@ var APPS_FIELDS_PREFIXED = [ 'apps.id', 'apps.appStoreId', 'apps.installationSta 'apps.health', 'apps.containerId', 'apps.manifestJson', 'apps.httpPort', 'apps.location', 'apps.domain', 'apps.dnsRecordId', 'apps.accessRestrictionJson', 'apps.restoreConfigJson', 'apps.oldConfigJson', 'apps.updateConfigJson', 'apps.memoryLimit', 'apps.xFrameOptions', 'apps.sso', 'apps.debugModeJson', 'apps.robotsTxt', 'apps.enableBackup', - 'apps.creationTime', 'apps.updateTime' ].join(','); + 'apps.creationTime', 'apps.updateTime', 'apps.ts' ].join(','); var PORT_BINDINGS_FIELDS = [ 'hostPort', 'environmentVariable', 'appId' ].join(','); diff --git a/src/apps.js b/src/apps.js index cb0a1961d..7f0d30414 100644 --- a/src/apps.js +++ b/src/apps.js @@ -336,7 +336,7 @@ function removeInternalFields(app) { function removeRestrictedFields(app) { return _.pick(app, 'id', 'appStoreId', 'installationState', 'installationProgress', 'runState', 'health', - 'location', 'domain', 'fqdn', 'manifest', 'portBindings', 'iconUrl', 'creationTime', 'updateTime'); + 'location', 'domain', 'fqdn', 'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts'); } function getIconUrlSync(app) { diff --git a/src/test/database-test.js b/src/test/database-test.js index 67144e107..7fa9157e6 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -823,7 +823,7 @@ describe('database', function () { appdb.get(APP_0.id, function (error, result) { expect(error).to.be(null); expect(result).to.be.an('object'); - expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0); + expect(_.omit(result, ['creationTime', 'updateTime', 'ts'])).to.be.eql(APP_0); done(); }); }); @@ -860,7 +860,7 @@ describe('database', function () { appdb.get(APP_0.id, function (error, result) { expect(error).to.be(null); expect(result).to.be.an('object'); - expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0); + expect(_.omit(result, ['creationTime', 'updateTime', 'ts'])).to.be.eql(APP_0); done(); }); }); @@ -870,7 +870,7 @@ describe('database', function () { appdb.getByHttpPort(APP_0.httpPort, function (error, result) { expect(error).to.be(null); expect(result).to.be.an('object'); - expect(_.omit(result, ['creationTime', 'updateTime'])).to.be.eql(APP_0); + expect(_.omit(result, ['creationTime', 'updateTime', 'ts'])).to.be.eql(APP_0); done(); }); }); @@ -895,8 +895,8 @@ describe('database', function () { expect(error).to.be(null); expect(result).to.be.an(Array); expect(result.length).to.be(2); - expect(_.omit(result[0], ['creationTime', 'updateTime'])).to.be.eql(APP_0); - expect(_.omit(result[1], ['creationTime', 'updateTime'])).to.be.eql(APP_1); + expect(_.omit(result[0], ['creationTime', 'updateTime','ts'])).to.be.eql(APP_0); + expect(_.omit(result[1], ['creationTime', 'updateTime','ts'])).to.be.eql(APP_1); done(); }); });