2021-07-07 10:46:50 +02:00
|
|
|
const { v4: uuid } = require('uuid');
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
exports.up = function (db, cb) {
|
2021-07-07 10:46:50 +02:00
|
|
|
db.runSql(
|
|
|
|
`SELECT *
|
|
|
|
FROM features`,
|
|
|
|
(err, results) => {
|
2021-08-12 15:04:37 +02:00
|
|
|
results.rows.forEach((feature) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
db.runSql(
|
2021-08-12 15:04:37 +02:00
|
|
|
'INSERT INTO feature_environments(feature_name, enabled) VALUES (?, ?)',
|
2021-07-07 10:46:50 +02:00
|
|
|
[feature.name, feature.enabled],
|
|
|
|
);
|
2021-08-12 15:04:37 +02:00
|
|
|
feature.strategies.forEach((strategy) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
db.runSql(
|
|
|
|
`INSERT INTO feature_strategies(id, feature_name, project_name, strategy_name, parameters, constraints)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
|
|
[
|
|
|
|
uuid(),
|
|
|
|
feature.name,
|
|
|
|
feature.project,
|
|
|
|
strategy.name,
|
|
|
|
JSON.stringify(strategy.parameters),
|
|
|
|
JSON.stringify(strategy.constraints),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
cb();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
exports.down = function (db, cb) {
|
2021-07-07 10:46:50 +02:00
|
|
|
db.runSql(
|
2021-08-12 15:04:37 +02:00
|
|
|
'DELETE FROM feature_strategies; DELETE FROM feature_environments;',
|
2021-07-07 10:46:50 +02:00
|
|
|
cb,
|
|
|
|
);
|
|
|
|
};
|