mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
migration:down should remove built_in strategies created in up
This commit is contained in:
parent
a25aa9fadd
commit
398f07f999
@ -23,6 +23,22 @@ function insertEventsSQL (strategy) {
|
|||||||
);`;
|
);`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeEventsSQL (strategy) {
|
||||||
|
return `
|
||||||
|
INSERT INTO events (type, created_by, data)
|
||||||
|
SELECT 'strategy-deleted', 'migration', '${JSON.stringify(strategy)}'
|
||||||
|
WHERE
|
||||||
|
EXISTS (
|
||||||
|
SELECT name FROM strategies WHERE name = '${strategy.name}' AND built_in = 1
|
||||||
|
);`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeStrategySQL (strategy) {
|
||||||
|
return `
|
||||||
|
DELETE FROM strategies
|
||||||
|
WHERE name = '${strategy.name}' AND built_in = 1`;
|
||||||
|
}
|
||||||
|
|
||||||
exports.up = function (db, callback) {
|
exports.up = function (db, callback) {
|
||||||
const insertStrategies = strategies.map((s) => (cb) => {
|
const insertStrategies = strategies.map((s) => (cb) => {
|
||||||
db.runSql(insertEventsSQL(s), cb);
|
db.runSql(insertEventsSQL(s), cb);
|
||||||
@ -31,6 +47,13 @@ exports.up = function (db, callback) {
|
|||||||
async.series(insertStrategies, callback);
|
async.series(insertStrategies, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.down = function (db, cb) {
|
exports.down = function (db, callback) {
|
||||||
return cb();
|
const removeStrategies = strategies
|
||||||
|
.filter(s => s.name !== 'default')
|
||||||
|
.map((s) => (cb) => {
|
||||||
|
db.runSql(removeEventsSQL(s), cb);
|
||||||
|
db.runSql(removeStrategySQL(s), cb);
|
||||||
|
});
|
||||||
|
|
||||||
|
async.series(removeStrategies, callback);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user