1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/migrations/20210615115226-migrate-strategies-to-feature-strategies.js
Christopher Kolstad ff7be7696c
fix: Stores as typescript and with interfaces. (#902)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-08-12 15:04:37 +02:00

39 lines
1.3 KiB
JavaScript

const { v4: uuid } = require('uuid');
exports.up = function (db, cb) {
db.runSql(
`SELECT *
FROM features`,
(err, results) => {
results.rows.forEach((feature) => {
db.runSql(
'INSERT INTO feature_environments(feature_name, enabled) VALUES (?, ?)',
[feature.name, feature.enabled],
);
feature.strategies.forEach((strategy) => {
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();
},
);
};
exports.down = function (db, cb) {
db.runSql(
'DELETE FROM feature_strategies; DELETE FROM feature_environments;',
cb,
);
};