const project = require('../config/project.config')
const server = require('../server/main')
const debug = require('debug')('app:bin:dev-server')
const db = require('sqlite')

// initialize database
Promise.resolve()
  .then(() => {
    db.open(project.path_database, { Promise })
    debug('Opened database file %s', project.path_database)
    server.listen(project.server_port)
    debug(`Server is now running at http://localhost:${project.server_port}.`)
  })
  .catch(err => debug(err.stack))

const project = require('../config/project.config')
const server = require('../server/main')
const debug = require('debug')('app:bin:dev-server')
const db = require('sqlite')

// open/init/migrate database and start koa server listen()
async function init () {
  try {
    debug('Opening database: %s', project.path_database)
    await db.open(project.path_database)

    debug('Running database migration checks')
    await db.migrate({
      // force: 'last',
      migrationsPath: project.paths.server('lib/migrations'),
    })

    server.listen(project.server_port)
    debug(`Server is now running at http://localhost:${project.server_port}.`)
  } catch (e) {
    debug(e)
    process.exit(1)
  }
}

init()

Add database migration/initialization on startup
Add database migration/initialization on startup
