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

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