mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
18 store feature when featureCreated-event is emitted
This commit is contained in:
parent
826f9d56e2
commit
03086cdd86
@ -2,10 +2,29 @@ var eventStore = require('./eventStore'),
|
|||||||
eventType = require('./eventType'),
|
eventType = require('./eventType'),
|
||||||
featuresMock = require('./featuresMock'),
|
featuresMock = require('./featuresMock'),
|
||||||
logger = require('./logger'),
|
logger = require('./logger'),
|
||||||
Promise = require('bluebird');
|
Promise = require('bluebird'),
|
||||||
|
dbPool = require('./dbPool');
|
||||||
|
/*
|
||||||
|
name varchar(255) PRIMARY KEY NOT NULL,
|
||||||
|
enabled integer default 0,
|
||||||
|
strategy_name varchar(255) references strategies(name),
|
||||||
|
parameters json
|
||||||
|
*/
|
||||||
|
|
||||||
eventStore.on(eventType.featureCreated, function (event) {
|
eventStore.on(eventType.featureCreated, function (event) {
|
||||||
logger.info('feature created event recieved', event);
|
var sql = 'INSERT INTO features(name, enabled, strategy_name, parameters) VALUES ($1, $2, $3, $4)';
|
||||||
|
var params = [
|
||||||
|
event.data.name,
|
||||||
|
event.data.enabled ? 1 : 0,
|
||||||
|
event.data.strategy,
|
||||||
|
event.data.parameters
|
||||||
|
];
|
||||||
|
|
||||||
|
dbPool.query(sql, params, function(err) {
|
||||||
|
if(err) {
|
||||||
|
logger.error('Could not insert feature, error was: ', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ CREATE TABLE features (
|
|||||||
created_at timestamp default now(),
|
created_at timestamp default now(),
|
||||||
name varchar(255) PRIMARY KEY NOT NULL,
|
name varchar(255) PRIMARY KEY NOT NULL,
|
||||||
enabled integer default 0,
|
enabled integer default 0,
|
||||||
strategy_name varchar(255) references strategies(name),
|
strategy_name varchar(255),
|
||||||
parameters json
|
parameters json
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user