Wait for db initialisation before starting app

This commit is contained in:
Petros Aggelatos 2013-12-23 04:24:40 +00:00 committed by Pablo Carranza Vélez
parent e5684a1c3a
commit dc3708d14f
2 changed files with 26 additions and 18 deletions

View File

@ -1,3 +1,4 @@
Promise = require 'bluebird'
Knex = require('knex') Knex = require('knex')
knex = Knex.initialize( knex = Knex.initialize(
@ -6,22 +7,24 @@ knex = Knex.initialize(
filename: '/supervisor/data/database.sqlite' filename: '/supervisor/data/database.sqlite'
) )
knex.schema.hasTable('config').then((exists) -> knex.init = Promise.all([
knex.schema.hasTable('config').then((exists) ->
if not exists if not exists
knex.schema.createTable('config', (t) -> knex.schema.createTable('config', (t) ->
t.string('key').primary() t.string('key').primary()
t.string('value') t.string('value')
) )
) )
knex.schema.hasTable('app').then((exists) ->
knex.schema.hasTable('app').then((exists) ->
if not exists if not exists
knex.schema.createTable('app', (t) -> knex.schema.createTable('app', (t) ->
t.increments('id').primary() t.increments('id').primary()
t.string('name') t.string('name')
t.string('containerId')
t.string('imageId') t.string('imageId')
t.string('status') t.boolean('privileged')
) )
) )
])
module.exports = knex module.exports = knex

View File

@ -1,2 +1,7 @@
require('coffee-script'); require('coffee-script');
require('./app'); var knex = require('./db')
// Wait for the DB schema to be created
knex.init.then(function () {
require('./app');
})