From b8399abee00d3a4a61ab94838e2a0c1472e63349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 26 Jan 2022 13:39:59 +0100 Subject: [PATCH] fix: add migration for old feature events (#1300) When we change the feature events we introduced a new column on the events table to ease resolving of feature related events, instead of knowing the types and require the data object to include a name property. This commit adds a migration to make sure we convert all feature events. fixes: #1299 --- ...220125200908-convert-old-feature-events.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/migrations/20220125200908-convert-old-feature-events.js diff --git a/src/migrations/20220125200908-convert-old-feature-events.js b/src/migrations/20220125200908-convert-old-feature-events.js new file mode 100644 index 0000000000..2525362e36 --- /dev/null +++ b/src/migrations/20220125200908-convert-old-feature-events.js @@ -0,0 +1,22 @@ +'use strict'; + +exports.up = function (db, cb) { + db.runSql( + ` + UPDATE events + SET feature_name = E.feature_name + FROM ( + SELECT id, data->>'name' AS feature_name + FROM events + WHERE type IN ('feature-created', 'feature-updated', 'feature-archived', 'feature-stale-on', 'feature-stale-off') + AND feature_name is null + ) AS E + WHERE events.id = E.id; + `, + cb, + ); +}; + +exports.down = function (db, cb) { + cb(); +};