diff --git a/migrations/20190923050431-apps-make-runState-not-null.js b/migrations/20190923050431-apps-make-runState-not-null.js new file mode 100644 index 000000000..74439db3f --- /dev/null +++ b/migrations/20190923050431-apps-make-runState-not-null.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('UPDATE apps SET runState=? WHERE runState IS NULL', [ 'running' ], function (error) { + if (error) return callback(error); + + db.runSql('ALTER TABLE apps MODIFY runState VARCHAR(512) NOT NULL', [], function (error) { + if (error) console.error(error); + callback(error); + }); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE app MODIFY runState VARCHAR(512)', [], function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index dd0265257..1061be7f0 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS apps( id VARCHAR(128) NOT NULL UNIQUE, appStoreId VARCHAR(128) NOT NULL, installationState VARCHAR(512) NOT NULL, // the active task on the app - runState VARCHAR(512), // if the app is stopped + runState VARCHAR(512) NOT NULL, // if the app is stopped health VARCHAR(128), healthTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, // when the app last responded containerId VARCHAR(128), diff --git a/src/test/database-test.js b/src/test/database-test.js index 511f0e3c7..3a15d6eda 100644 --- a/src/test/database-test.js +++ b/src/test/database-test.js @@ -394,7 +394,7 @@ describe('database', function () { appStoreId: 'appStoreId-0', installationState: apps.ISTATE_PENDING_INSTALL, error: null, - runState: null, + runState: 'running', location: 'some-location-0', domain: DOMAIN_0.domain, manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' }, @@ -972,7 +972,7 @@ describe('database', function () { appStoreId: 'appStoreId-0', installationState: apps.ISTATE_PENDING_INSTALL, error: null, - runState: null, + runState: 'running', location: 'some-location-0', domain: DOMAIN_0.domain, manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' }, @@ -1003,7 +1003,7 @@ describe('database', function () { appStoreId: 'appStoreId-1', installationState: apps.ISTATE_PENDING_INSTALL, // app health tests rely on this initial state error: null, - runState: null, + runState: 'running', location: 'some-location-1', domain: DOMAIN_0.domain, manifest: { version: '0.2', dockerImage: 'docker/app1', healthCheckPath: '/', httpPort: 80, title: 'app1' },