1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Strategy should use better param description

Adds support for more fields sucha as description, required, etc.

relates to #182
This commit is contained in:
ivaosthu 2016-12-12 16:52:20 +01:00 committed by Ivar Conradi Østhus
parent 97f6731140
commit 082d5068a8
3 changed files with 72 additions and 3 deletions

View File

@ -59,11 +59,14 @@ npm test
We use database migrations to track database changes. We use database migrations to track database changes.
### Making a schema change ### Making a schema change
In order to run migrations you will set the environment variable for DATABASE_URL
`export DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash`
Use db-migrate to create new migrations file. Use db-migrate to create new migrations file.
```bash ```bash
> ./node_modules/.bin/db-migrate create your-migration-name > npm run db-migrate -- create YOUR-MIGRATION-NAME
``` ```
All migrations requires on `up` and one `down` method. All migrations requires on `up` and one `down` method.
@ -86,6 +89,12 @@ exports.down = function (db, cb) {
}; };
``` ```
Test your migrations:
```bash
> npm run db-migrate -- up
> npm run db-migrate -- down
```
## Publishing / Releasing new packages ## Publishing / Releasing new packages

View File

@ -0,0 +1,61 @@
/* eslint camelcase: "off" */
'use strict';
const async = require('async');
exports.up = function (db, callback) {
const populateNewData = (cb) => {
db.all('select name, parameters_template from strategies', (err, results) => {
const updateSQL = results
.map(({ name, parameters_template }) => {
const parameters = [];
Object.keys(parameters_template || {}).forEach(p => {
parameters.push({ name: p, type: parameters_template[p], description: '' });
});
return { name, parameters };
})
.map(strategy => `
UPDATE strategies
SET parameters='${JSON.stringify(strategy.parameters)}'
WHERE name='${strategy.name}';`)
.join('\n');
db.runSql(updateSQL, cb);
});
};
async.series([
db.addColumn.bind(db, 'strategies', 'parameters', { type: 'json' }),
populateNewData.bind(db),
db.removeColumn.bind(db, 'strategies', 'parameters_template'),
], callback);
};
exports.down = function (db, callback) {
const populateOldData = (cb) => {
db.all('select name, parameters from strategies', (err, results) => {
const updateSQL = results
.map(({ name, parameters }) => {
const parameters_template = {};
parameters.forEach(p => {
parameters_template[p.name] = p.type;
});
return { name, parameters_template };
})
.map(strategy => `
UPDATE strategies
SET parameters_template='${JSON.stringify(strategy.parameters_template)}'
WHERE name='${strategy.name}';`)
.join('\n');
db.runSql(updateSQL, cb);
});
};
async.series([
db.addColumn.bind(db, 'strategies', 'parameters_template', { type: 'json' }),
populateOldData.bind(db),
db.removeColumn.bind(db, 'strategies', 'parameters'),
], callback);
};

View File

@ -37,8 +37,7 @@
"start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ server.js", "start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ server.js",
"start:dev:pg": "pg_virtualenv npm run start:dev:pg-chain", "start:dev:pg": "pg_virtualenv npm run start:dev:pg-chain",
"start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev", "start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev",
"db-migrate": "db-migrate up", "db-migrate": "db-migrate",
"db-migrate:down": "db-migrate down",
"lint": "eslint lib", "lint": "eslint lib",
"pretest": "npm run lint", "pretest": "npm run lint",
"test": "PORT=4243 ava test lib/*.test.js lib/**/*.test.js", "test": "PORT=4243 ava test lib/*.test.js lib/**/*.test.js",