1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00

Add default built-in strategies.

Uses migration to define these activation strategies:
- applicationHostname
- gradualRolloutRandom
- gradualRolloutSessionId
- gradualRolloutUserId
- remoteAddress
- userWithId

closes #207
This commit is contained in:
Ivar 2017-02-11 11:17:11 +01:00
parent f2bb16e195
commit 9e541bd7e6
3 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,15 @@
/* eslint camelcase: "off" */
'use strict';
const async = require('async');
exports.up = function (db, cb) {
async.series([
db.addColumn.bind(db, 'strategies', 'built_in', { type: 'int', defaultValue: 0 }),
db.runSql.bind(db, 'UPDATE strategies SET built_in=1 where name=\'default\''),
], cb);
};
exports.down = function (db, cb) {
return db.removeColumn('strategies', 'built_in', cb);
};

View File

@ -0,0 +1,37 @@
/* eslint camelcase: "off" */
'use strict';
const strategies = require('./default-strategies.json');
const async = require('async');
function insertStrategySQL (strategy) {
return `
INSERT INTO strategies (name, description, parameters, built_in)
SELECT '${strategy.name}', '${strategy.description}', '${JSON.stringify(strategy.parameters)}', 1
WHERE
NOT EXISTS (
SELECT name FROM strategies WHERE name = '${strategy.name}'
);`;
}
function insertEventsSQL (strategy) {
return `
INSERT INTO events (type, created_by, data)
SELECT 'strategy-created', 'migration', '${JSON.stringify(strategy)}'
WHERE
NOT EXISTS (
SELECT name FROM strategies WHERE name = '${strategy.name}'
);`;
}
exports.up = function (db, callback) {
const insertStrategies = strategies.map((s) => (cb) => {
db.runSql(insertEventsSQL(s), cb);
db.runSql(insertStrategySQL(s), cb);
});
async.series(insertStrategies, callback);
};
exports.down = function (db, cb) {
return cb();
};

View File

@ -0,0 +1,77 @@
[
{
"name": "default",
"description": "Default on/off strategy.",
"parameters": []
},
{
"name": "userWithId",
"description": "Active for users with a userId defined in the userIds-list",
"parameters": [{
"name": "userIds",
"type": "list",
"description": "",
"required": false
}]
},
{
"name": "applicationHostname",
"description": "Active for client instances with a hostName in the hostNames-list.",
"parameters": [{
"name": "hostNames",
"type": "list",
"description": "List of hostnames to enable the feature toggle for.",
"required": false
}]
},
{
"name": "gradualRolloutRandom",
"description": "Randomly activate the feature toggle. No stickiness.",
"parameters": [{
"name": "percentage",
"type": "percentage",
"description": "",
"required": false
}]
},
{
"name": "gradualRolloutSessionId",
"description": "Gradually activate feature toggle. Stickiness based on session id.",
"parameters": [{
"name": "percentage",
"type": "percentage",
"description": "",
"required": false
},{
"name": "groupId",
"type": "string",
"description": "Used to define a activation groups, which allows you to correlate across feature toggles.",
"required": true
}]
},
{
"name": "gradualRolloutUserId",
"description": "Gradually activate feature toggle for logged in users. Stickiness based on user id.",
"parameters": [{
"name": "percentage",
"type": "percentage",
"description": "",
"required": false
},{
"name": "groupId",
"type": "string",
"description": "Used to define a activation groups, which allows you to correlate across feature toggles.",
"required": true
}]
},
{
"name": "remoteAddress",
"description": "Active for remote addresses defined in the IPs list.",
"parameters": [{
"name": "IPs",
"type": "list",
"description": "List of IPs to enable the feature toggle for.",
"required": true
}]
}
]