fix: Store and retrieve device config without namespaces

This avoids issues on provisioning where the current state
(esp. config.txt) that we want to save is retrieved without
a RESIN_ or BALENA_ prefix, causing those values to be lost.

Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
This commit is contained in:
Pablo Carranza Velez
2018-10-20 04:26:14 +02:00
parent cb31474d7a
commit b3860b2b70
5 changed files with 48 additions and 27 deletions

20
src/migrations/M00000.js Normal file
View File

@ -0,0 +1,20 @@
const _ = require('lodash');
// We take legacy deviceConfig targets and store them without the RESIN_ prefix
// (we also strip the BALENA_ prefix for completeness, even though no supervisors
// using this prefix made it to production)
exports.up = function (knex, Promise) {
return knex('deviceConfig').select('targetValues')
.then((devConfigs) => {
const devConfig = devConfigs[0];
const targetValues = JSON.parse(devConfig.targetValues);
const filteredTargetValues = _.mapKeys( (_v, k) => {
return k.replace(/^(?:RESIN|BALENA)_(.*)/, '$1');
});
return knex('deviceConfig').update({ targetValues: JSON.stringify(filteredTargetValues) });
});
}
exports.down = function (knex, Promise) {
return Promise.reject(new Error('Not Implemented'));
}