From 16a2542b374117325b8168ebbbcf0b1b4690e74b Mon Sep 17 00:00:00 2001 From: sjaanus Date: Wed, 21 Aug 2024 14:17:42 +0300 Subject: [PATCH] fix: fix events with no-project projects --- ...240821141555-segment-no-project-cleanup.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/migrations/20240821141555-segment-no-project-cleanup.js diff --git a/src/migrations/20240821141555-segment-no-project-cleanup.js b/src/migrations/20240821141555-segment-no-project-cleanup.js new file mode 100644 index 000000000000..75abd5a8f5e4 --- /dev/null +++ b/src/migrations/20240821141555-segment-no-project-cleanup.js @@ -0,0 +1,25 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + UPDATE events + SET project = NULL + WHERE type = 'segment-created' + AND project = 'no-project' + AND NOT EXISTS ( + SELECT 1 + FROM projects + WHERE name = 'no-project' + ); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ``, + callback, + ); +};