From 68f9341e955380cccd9f3df4a169f5fc19c0c09f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 19 May 2022 15:40:48 +0200 Subject: [PATCH] hotfix: uniform color migration fix --- .../migration/1652859567549-uniform-themecolor.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/backend/migration/1652859567549-uniform-themecolor.js b/packages/backend/migration/1652859567549-uniform-themecolor.js index bc47143e5..8da1fd7fb 100644 --- a/packages/backend/migration/1652859567549-uniform-themecolor.js +++ b/packages/backend/migration/1652859567549-uniform-themecolor.js @@ -6,27 +6,25 @@ export class uniformThemecolor1652859567549 { async up(queryRunner) { const formatColor = (color) => { let tc = new tinycolor(color); - if (color.isValid()) { - return color.toHexString(); + if (tc.isValid()) { + return tc.toHexString(); } else { return null; } }; - await Promise.all(queryRunner.query('SELECT "id", "themeColor" FROM "instance" WHERE "themeColor" IS NOT NULL') - .then(instances => instances.map(instance => { + await queryRunner.query('SELECT "id", "themeColor" FROM "instance" WHERE "themeColor" IS NOT NULL') + .then(instances => Promise.all(instances.map(instance => { // update theme color to uniform format, e.g. #00ff00 // invalid theme colors get set to null - instance.color = formatColor(instance.color); - - return queryRunner.query('UPDATE "instance" SET "themeColor" = :themeColor WHERE "id" = :id', instance); + return queryRunner.query('UPDATE "instance" SET "themeColor" = $1 WHERE "id" = $2', [formatColor(instance.themeColor), instance.id]); }))); // also fix own theme color await queryRunner.query('SELECT "themeColor" FROM "meta" WHERE "themeColor" IS NOT NULL LIMIT 1') .then(metas => { if (metas.length > 0) { - return queryRunner.query('UPDATE "meta" SET "themeColor" = :color', { color: formatColor(metas[0].color) }); + return queryRunner.query('UPDATE "meta" SET "themeColor" = $1', [formatColor(metas[0].themeColor)]); } }); }