2016-07-02 16:25:30 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2017-06-28 14:10:32 +02:00
|
|
|
exports.up = function(db, callback) {
|
|
|
|
db.runSql(
|
|
|
|
`
|
2016-12-10 11:35:13 +01:00
|
|
|
--create new strategies-column
|
|
|
|
ALTER TABLE features ADD "strategies" json;
|
|
|
|
|
|
|
|
--populate the strategies column
|
|
|
|
UPDATE features
|
|
|
|
SET strategies = ('[{"name":"'||f.strategy_name||'","parameters":'||f.parameters||'}]')::json
|
|
|
|
FROM features as f
|
|
|
|
WHERE f.name = features.name;
|
|
|
|
|
|
|
|
--delete old strategy-columns
|
|
|
|
ALTER TABLE features DROP COLUMN "strategy_name";
|
|
|
|
ALTER TABLE features DROP COLUMN "parameters";
|
2017-06-28 14:10:32 +02:00
|
|
|
`,
|
2020-04-14 22:29:11 +02:00
|
|
|
callback,
|
2017-06-28 14:10:32 +02:00
|
|
|
);
|
2016-12-10 11:35:13 +01:00
|
|
|
};
|
|
|
|
|
2017-06-28 14:10:32 +02:00
|
|
|
exports.down = function(db, callback) {
|
|
|
|
db.runSql(
|
|
|
|
`
|
2016-12-10 11:35:13 +01:00
|
|
|
--create old columns
|
|
|
|
ALTER TABLE features ADD "parameters" json;
|
|
|
|
ALTER TABLE features ADD "strategy_name" varchar(255);
|
|
|
|
|
|
|
|
--populate old columns
|
|
|
|
UPDATE features
|
|
|
|
SET strategy_name = f.strategies->0->>'name',
|
|
|
|
parameters = f.strategies->0->'parameters'
|
|
|
|
FROM features as f
|
|
|
|
WHERE f.name = features.name;
|
|
|
|
|
|
|
|
--drop new column
|
|
|
|
ALTER TABLE features DROP COLUMN "strategies";
|
2017-06-28 14:10:32 +02:00
|
|
|
`,
|
2020-04-14 22:29:11 +02:00
|
|
|
callback,
|
2017-06-28 14:10:32 +02:00
|
|
|
);
|
2016-12-10 11:35:13 +01:00
|
|
|
};
|