diff --git a/unleash-server/lib/featureDb.js b/unleash-server/lib/featureDb.js index 282ec66ec7..522146f011 100644 --- a/unleash-server/lib/featureDb.js +++ b/unleash-server/lib/featureDb.js @@ -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); + } + }); } ); diff --git a/unleash-server/migrations/sql/001-initial-schema.up.sql b/unleash-server/migrations/sql/001-initial-schema.up.sql index a4d6e72056..5af3577f36 100644 --- a/unleash-server/migrations/sql/001-initial-schema.up.sql +++ b/unleash-server/migrations/sql/001-initial-schema.up.sql @@ -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 );