mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-21 22:47:49 +00:00
Wait for db initialisation before starting app
This commit is contained in:
parent
e5684a1c3a
commit
dc3708d14f
@ -1,3 +1,4 @@
|
||||
Promise = require 'bluebird'
|
||||
Knex = require('knex')
|
||||
|
||||
knex = Knex.initialize(
|
||||
@ -6,22 +7,24 @@ knex = Knex.initialize(
|
||||
filename: '/supervisor/data/database.sqlite'
|
||||
)
|
||||
|
||||
knex.schema.hasTable('config').then((exists) ->
|
||||
if not exists
|
||||
knex.schema.createTable('config', (t) ->
|
||||
t.string('key').primary()
|
||||
t.string('value')
|
||||
)
|
||||
)
|
||||
|
||||
knex.schema.hasTable('app').then((exists) ->
|
||||
if not exists
|
||||
knex.schema.createTable('app', (t) ->
|
||||
t.increments('id').primary()
|
||||
t.string('name')
|
||||
t.string('imageId')
|
||||
t.string('status')
|
||||
)
|
||||
)
|
||||
knex.init = Promise.all([
|
||||
knex.schema.hasTable('config').then((exists) ->
|
||||
if not exists
|
||||
knex.schema.createTable('config', (t) ->
|
||||
t.string('key').primary()
|
||||
t.string('value')
|
||||
)
|
||||
)
|
||||
knex.schema.hasTable('app').then((exists) ->
|
||||
if not exists
|
||||
knex.schema.createTable('app', (t) ->
|
||||
t.increments('id').primary()
|
||||
t.string('name')
|
||||
t.string('containerId')
|
||||
t.string('imageId')
|
||||
t.boolean('privileged')
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
module.exports = knex
|
||||
|
@ -1,2 +1,7 @@
|
||||
require('coffee-script');
|
||||
require('./app');
|
||||
var knex = require('./db')
|
||||
|
||||
// Wait for the DB schema to be created
|
||||
knex.init.then(function () {
|
||||
require('./app');
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user