Fix error applying device configuration because deviceConfig table is empty

If there's no entries in deviceConfig table, always create one.

Avoids problems if the supervisor is stopped while running the db initialization
(deviceConfig gets created but not populated).

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2016-12-05 17:59:04 -03:00
parent 7006f58267
commit c67977cbed

View File

@ -29,7 +29,9 @@ knex.init = Promise.all([
t.json('values') t.json('values')
t.json('targetValues') t.json('targetValues')
.then -> .then ->
knex('deviceConfig').insert({ values: '{}', targetValues: '{}' }) knex('deviceConfig').select()
.then (deviceConfigs) ->
knex('deviceConfig').insert({ values: '{}', targetValues: '{}' }) if deviceConfigs.length == 0
knex.schema.hasTable('app') knex.schema.hasTable('app')
.then (exists) -> .then (exists) ->