ToolJet/server/data-migrations/1736921797727-MoveInstanceWhiteLabelsToWhiteLabelsEntity.ts

57 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-02-25 06:52:50 +00:00
import { In, MigrationInterface, QueryRunner } from 'typeorm';
import { InstanceSettings } from '@entities/instance_settings.entity';
import { WhiteLabelling } from '@entities/white_labelling.entity';
import { WHITE_LABELLING_SETTINGS } from '@helpers/migration.helper';
2025-08-03 07:09:18 +00:00
import { getTooljetEdition } from '@helpers/utils.helper';
import { TOOLJET_EDITIONS } from '@modules/app/constants';
2025-02-25 06:52:50 +00:00
export class MoveInstanceWhiteLabelsToWhiteLabelsEntity1736921797727 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
2025-08-03 07:09:18 +00:00
if (getTooljetEdition() !== TOOLJET_EDITIONS.EE) {
console.log('Skipping migration as it is not EE edition');
return;
}
2025-02-25 06:52:50 +00:00
const entityManager = queryRunner.manager;
// Get all white label related settings
const whiteLabelSettings = await entityManager.find(InstanceSettings, {
where: {
key: In([
WHITE_LABELLING_SETTINGS.WHITE_LABEL_FAVICON,
WHITE_LABELLING_SETTINGS.WHITE_LABEL_LOGO,
WHITE_LABELLING_SETTINGS.WHITE_LABEL_TEXT,
]),
},
});
// Create new white label records
if (whiteLabelSettings.length > 0) {
const whiteLabel = new WhiteLabelling();
whiteLabelSettings.forEach((setting) => {
switch (setting.key) {
case WHITE_LABELLING_SETTINGS.WHITE_LABEL_FAVICON:
whiteLabel.favicon = setting.value;
break;
case WHITE_LABELLING_SETTINGS.WHITE_LABEL_LOGO:
whiteLabel.logo = setting.value;
break;
case WHITE_LABELLING_SETTINGS.WHITE_LABEL_TEXT:
whiteLabel.text = setting.value;
break;
}
});
await entityManager.save(WhiteLabelling, whiteLabel);
// Remove old settings
await entityManager.delete(InstanceSettings, {
key: In([
WHITE_LABELLING_SETTINGS.WHITE_LABEL_FAVICON,
WHITE_LABELLING_SETTINGS.WHITE_LABEL_LOGO,
WHITE_LABELLING_SETTINGS.WHITE_LABEL_TEXT,
]),
});
}
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}