Skip to content

Commit

Permalink
Merge branch 'check-pending-migrations'
Browse files Browse the repository at this point in the history
  • Loading branch information
jajm committed Apr 10, 2019
2 parents 49b7090 + d47a0ea commit e24598e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -13,4 +13,6 @@ before_install:
- mysql -e 'GRANT ALL ON urungi_tests.* TO urungi@localhost IDENTIFIED BY "urungi"'
- psql -c 'create database urungi_tests;' -U postgres
- npm i -g npm
before_script:
- npx migrate-mongo up
cache: npm
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -41,6 +41,11 @@ not going to explore MondoDB data.
npm ci
```

4. Run MongoDB migrations

```
npx migrate-mongo up
```

## Configuration

Expand Down
29 changes: 21 additions & 8 deletions server.js
@@ -1,16 +1,29 @@
const debug = require('debug')('urungi:server');
const cluster = require('cluster');
const migrate = require('migrate-mongo');

if (cluster.isMaster && process.env.NODE_ENV !== 'test') {
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
migrate.database.connect().then(db => {
return migrate.status(db).then(statuses => {
db.close();
if (statuses.some(s => s.appliedAt === 'PENDING')) {
throw new Error('Some migrations are pending. Run `npx migrate-mongo up` before starting the server');
}
});
}).then(function () {
var numCPUs = require('os').cpus().length;

// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', function (deadWorker, code, signal) {
cluster.fork();
cluster.on('exit', function (deadWorker, code, signal) {
cluster.fork();
});
}, function (error) {
console.error('Error: ' + error.message);
process.exitCode = 1;
});
} else {
const app = require('./app');
Expand Down

0 comments on commit e24598e

Please sign in to comment.