Skip to content

Commit

Permalink
Fix migration issue (#81)
Browse files Browse the repository at this point in the history
* testing new migration facility

* fixed travis build

* fixed migration issue, now migration / resetdb are the part of npm run instead of postinstall

* removed isherokuprivatespace

* removed checkorupdateprivatedb script

* removed console.log and resolved conflict
  • Loading branch information
harshkothari410 authored and pallavi2209 committed Nov 3, 2016
1 parent 0c5678a commit d3dded2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 78 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ services:
- redis-server

script:
- npm run checkdb
- npm test

22 changes: 1 addition & 21 deletions db/createOrUpdateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,18 @@ const models = require('./index');
const pgtools = require('pgtools');
const utils = require('./utils');

/*
* If this is running in a Heroku Private Space, just exit (ref.
* createOrUpdatePrivateDb.js).
*/
if (utils.isInHerokuPrivateSpace()) {
console.log('Exiting "./db/createOrUpdateDb" because db is running in a ' +
'Heroku Private Space');
process.exit(0); // eslint-disable-line
}

console.log('querying information_schema.tables where table_schema = \'public\'')
models.sequelize.query(`select count(*) from
information_schema.tables where table_schema = 'public'`)
.then((data) => {
console.log('found', data)
if (data[0][0].count === '0') { // eslint-disable-line
require('./reset.js'); // eslint-disable-line global-require
} else {
require('./migrate.js'); // eslint-disable-line global-require
}
})
.catch((err) => {
console.log('caught err', err);
if (err.name === 'SequelizeConnectionError' &&
err.message.startsWith('connect ETIMEDOUT')) {
console.log('Exiting "./db/createOrUpdateDb"... ' +
'SequelizeConnectionError: connect ETIMEDOUT');
process.exit(0); // eslint-disable-line
}

const dbConfig = utils.dbConfigObjectFromDbURL();
console.log('create db now', dbConfig)
console.log('create db now', dbConfig.name); // eslint-disable-line
pgtools.createdb(dbConfig, dbConfig.name, (err2, res) => {
if (err2) {
console.error('ERROR', err2); // eslint-disable-line
Expand Down
41 changes: 0 additions & 41 deletions db/createOrUpdatePrivateDb.js

This file was deleted.

13 changes: 0 additions & 13 deletions db/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ function dbConfigObjectFromDbURL() {
};
} // dbConfigObjectFromDbURL

// check whether host is in private space of heroku or not
function isInHerokuPrivateSpace() {
// Temporary workaround since the regex stopped working.
console.log('Running in Heroku Private Space? ',
env.isInHerokuPrivateSpace || false);
return env.isInHerokuPrivateSpace || false;
// const rx = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|$)){4}$/;
// const dbConfig = dbConfigObjectFromDbURL();
// console.log('dbConfig', dbConfig)
// return rx.test(dbConfig.host);
} // isInHerokuPrivateSpace

function initializeAdminUserAndProfile(seq) {
var pid;
return seq.models.Profile.upsert(conf.db.adminProfile)
Expand Down Expand Up @@ -78,5 +66,4 @@ function initializeAdminUserAndProfile(seq) {
module.exports = {
dbConfigObjectFromDbURL,
initializeAdminUserAndProfile,
isInHerokuPrivateSpace,
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"resetdb": "node db/reset.js",
"migratedb": "node db/migrate.js",
"checkdb": "node db/createOrUpdateDb.js",
"checkprivatedb": "node db/createOrUpdatePrivateDb",
"undo-migratedb": "node db/migrateUndo.js",
"test-api": "mocha -R dot --recursive tests/api",
"test-disablehttp": "DISABLE_HTTP=true mocha -R dot --recursive tests/disableHttp",
Expand All @@ -36,8 +35,8 @@
"test-realtime": "mocha -R dot --recursive tests/realtime",
"test-view": "NODE_ENV=test mocha -R dot --recursive --compilers js:babel-core/register --require ./tests/view/setup.js tests/view",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/db tests/config && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-realtime && npm run test-token-req && npm run test-token-notreq && npm run test-disablehttp",
"postinstall": "NODE_ENV=production gulp browserifyViews && gulp movecss && gulp movesocket && gulp movelensutil && npm run checkdb",
"prestart": "npm run checkprivatedb"
"postinstall": "NODE_ENV=production gulp browserifyViews && gulp movecss && gulp movesocket && gulp movelensutil",
"prestart": "npm run checkdb"
},
"dependencies": {
"@risingstack/trace": "^2.25.0",
Expand Down

0 comments on commit d3dded2

Please sign in to comment.