2018-05-17 09:40:36 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const configJsonPath = process.env.CONFIG_MOUNT_POINT;
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
exports.up = function (knex) {
|
|
|
|
return new Promise((resolve) => {
|
2018-05-17 09:40:36 +00:00
|
|
|
if (!configJsonPath) {
|
2020-03-23 18:42:27 +00:00
|
|
|
console.log(
|
|
|
|
'Unable to locate config.json! Things may fail unexpectedly!',
|
|
|
|
);
|
2020-03-24 14:21:17 +00:00
|
|
|
return resolve({});
|
2018-05-17 09:40:36 +00:00
|
|
|
}
|
|
|
|
fs.readFile(configJsonPath, (err, data) => {
|
|
|
|
if (err) {
|
2020-03-23 18:42:27 +00:00
|
|
|
console.log(
|
|
|
|
'Failed to read config.json! Things may fail unexpectedly!',
|
|
|
|
);
|
2018-05-17 09:40:36 +00:00
|
|
|
resolve({});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const parsed = JSON.parse(data.toString());
|
|
|
|
resolve(parsed);
|
2020-03-23 18:42:27 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log(
|
|
|
|
'Failed to parse config.json! Things may fail unexpectedly!',
|
|
|
|
);
|
2018-05-17 09:40:36 +00:00
|
|
|
resolve({});
|
|
|
|
}
|
|
|
|
});
|
2020-05-15 11:01:51 +00:00
|
|
|
}).then((config) => {
|
2020-03-23 18:42:27 +00:00
|
|
|
return knex.schema
|
2020-05-15 11:01:51 +00:00
|
|
|
.table('app', (t) => {
|
2018-05-17 09:40:36 +00:00
|
|
|
// Create a new column on the table and add the apiEndpoint config json
|
|
|
|
// field if it exists
|
|
|
|
t.string('source');
|
|
|
|
})
|
2020-03-23 18:42:27 +00:00
|
|
|
.then(() => {
|
|
|
|
return knex('app').update({ source: config.apiEndpoint || '' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2018-05-17 09:40:36 +00:00
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
exports.down = function () {
|
2020-03-23 18:42:27 +00:00
|
|
|
return Promise.reject(new Error('Not Implemented'));
|
|
|
|
};
|