nfp_sites/api/setup.mjs

29 lines
746 B
JavaScript
Raw Normal View History

2019-02-19 11:34:52 +00:00
import _ from 'lodash'
2019-09-14 19:03:38 +00:00
import config from './config.mjs'
import log from './log.mjs'
2019-02-19 11:34:52 +00:00
import knex from 'knex'
// This is important for setup to run cleanly.
let knexConfig = _.cloneDeep(config.get('knex'))
knexConfig.pool = { min: 1, max: 1 }
let knexSetup = knex(knexConfig)
export default function setup() {
log.info(knexConfig, 'Running database integrity scan.')
return knexSetup.migrate.latest({
directory: './migrations',
})
.then((result) => {
if (result[1].length === 0) {
return log.info('Database is up to date')
}
for (let i = 0; i < result[1].length; i++) {
log.info('Applied migration from', result[1][i].substr(result[1][i].lastIndexOf('\\') + 1))
}
return knexSetup.destroy()
})
}