mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
18 store feature when featureCreated-event is emitted
This commit is contained in:
parent
c991fed69c
commit
1a421f395d
@ -2,10 +2,29 @@ var eventStore = require('./eventStore'),
|
||||
eventType = require('./eventType'),
|
||||
featuresMock = require('./featuresMock'),
|
||||
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) {
|
||||
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(),
|
||||
name varchar(255) PRIMARY KEY NOT NULL,
|
||||
enabled integer default 0,
|
||||
strategy_name varchar(255) references strategies(name),
|
||||
strategy_name varchar(255),
|
||||
parameters json
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user