hotfix: uniform color migration fix

This commit is contained in:
Johann150 2022-05-19 15:40:48 +02:00
parent be1d02a7f8
commit 68f9341e95
No known key found for this signature in database
GPG Key ID: 9EE6577A2A06F8F1
1 changed files with 6 additions and 8 deletions

View File

@ -6,27 +6,25 @@ export class uniformThemecolor1652859567549 {
async up(queryRunner) { async up(queryRunner) {
const formatColor = (color) => { const formatColor = (color) => {
let tc = new tinycolor(color); let tc = new tinycolor(color);
if (color.isValid()) { if (tc.isValid()) {
return color.toHexString(); return tc.toHexString();
} else { } else {
return null; return null;
} }
}; };
await Promise.all(queryRunner.query('SELECT "id", "themeColor" FROM "instance" WHERE "themeColor" IS NOT NULL') await queryRunner.query('SELECT "id", "themeColor" FROM "instance" WHERE "themeColor" IS NOT NULL')
.then(instances => instances.map(instance => { .then(instances => Promise.all(instances.map(instance => {
// update theme color to uniform format, e.g. #00ff00 // update theme color to uniform format, e.g. #00ff00
// invalid theme colors get set to null // invalid theme colors get set to null
instance.color = formatColor(instance.color); return queryRunner.query('UPDATE "instance" SET "themeColor" = $1 WHERE "id" = $2', [formatColor(instance.themeColor), instance.id]);
return queryRunner.query('UPDATE "instance" SET "themeColor" = :themeColor WHERE "id" = :id', instance);
}))); })));
// also fix own theme color // also fix own theme color
await queryRunner.query('SELECT "themeColor" FROM "meta" WHERE "themeColor" IS NOT NULL LIMIT 1') await queryRunner.query('SELECT "themeColor" FROM "meta" WHERE "themeColor" IS NOT NULL LIMIT 1')
.then(metas => { .then(metas => {
if (metas.length > 0) { 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)]);
} }
}); });
} }