From fd659c88c6c80bd7767b049ace1bb65d5ee4ef38 Mon Sep 17 00:00:00 2001 From: Neal Conner Date: Thu, 3 May 2018 09:46:10 +0100 Subject: [PATCH] Fix migrate-tools for multiple devices (#113) Don't fail with duplicate key errors if there is more than one row already in the devices table, since it attempts to update the device_id column. --- migrations/migrate-tools.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/migrate-tools.js b/migrations/migrate-tools.js index e1d76e99..cb8132b0 100644 --- a/migrations/migrate-tools.js +++ b/migrations/migrate-tools.js @@ -7,10 +7,10 @@ const machineLoader = require('../lib/machine-loader') module.exports = {migrateNames} function migrateNames () { - const cs = new pgp.helpers.ColumnSet(['device_id', 'name'], {table: 'devices'}) + 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)) + .then(data => pgp.helpers.update(data, cs) + ' WHERE t.device_id=v.device_id') }