fix migration so it doesn't error out on existing devices

This commit is contained in:
Josh Harvey 2017-12-19 18:55:14 +02:00
parent 2b3e49fdab
commit d3c2448a12
2 changed files with 29 additions and 5 deletions

View file

@ -0,0 +1,16 @@
const pgp = require('pg-promise')()
const _ = require('lodash/fp')
const settingsLoader = require('../lib/settings-loader')
const machineLoader = require('../lib/machine-loader')
module.exports = {migrateNames}
function migrateNames () {
const cs = new pgp.helpers.ColumnSet(['device_id', 'name'], {table: 'devices'})
return settingsLoader.loadLatest()
.then(r => machineLoader.getMachineNames(r.config))
.then(_.map(r => ({device_id: r.deviceId, name: r.name})))
.then(data => pgp.helpers.update(data, cs))
}