DemocracyOS/democracyos

View on GitHub
bin/dos-migrate

Summary

Maintainability
Test Coverage
#!/usr/bin/env node

const Migrator = require('migrate-mongoose')
const config = require('../lib/config')

const migrator = new Migrator({
  dbConnectionUri: config.mongoUrl,
  autosync: true,
  cli: true
})

process.on('SIGINT', () => {
  migrator.close().then(() => {
    process.exit(0)
  }).catch((err) => {
    console.error(err)
  })
})

process.on('exit', () => {
  migrator.close()
})

migrator.run()
  .then(() => { process.exit(0) })
  .catch((err) => {
    const doneError = new Error('There are no migrations to run').toString()
    if (err && err.toString() === doneError) process.exit(0)

    console.error(err)
    process.exit(1)
  })