2025-07-13 11:17:41 +00:00
|
|
|
import { Component } from '@entities/component.entity';
|
|
|
|
|
import { processDataInBatches } from '@helpers/migration.helper';
|
|
|
|
|
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
|
export class MigrateFormVisibilityHeaderFooterProperties1752403387878 implements MigrationInterface {
|
|
|
|
|
|
2025-07-15 15:37:46 +00:00
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
|
|
|
const componentTypes = ['Form'];
|
|
|
|
|
const batchSize = 100;
|
|
|
|
|
const entityManager = queryRunner.manager;
|
|
|
|
|
|
|
|
|
|
for (const componentType of componentTypes) {
|
|
|
|
|
await processDataInBatches(
|
|
|
|
|
entityManager,
|
|
|
|
|
async (entityManager: EntityManager) => {
|
|
|
|
|
return await entityManager.find(Component, {
|
|
|
|
|
where: { type: componentType },
|
|
|
|
|
order: { createdAt: 'ASC' },
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
async (entityManager: EntityManager, components: Component[]) => {
|
|
|
|
|
await this.processUpdates(entityManager, components);
|
|
|
|
|
},
|
|
|
|
|
batchSize
|
|
|
|
|
);
|
2025-07-13 11:17:41 +00:00
|
|
|
}
|
2025-07-15 15:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async processUpdates(entityManager, components) {
|
|
|
|
|
for (const component of components) {
|
|
|
|
|
const properties = component.properties;
|
|
|
|
|
const styles = component.styles;
|
|
|
|
|
const general = component.general;
|
|
|
|
|
const generalStyles = component.generalStyles;
|
|
|
|
|
|
|
|
|
|
if (styles?.visibility) {
|
|
|
|
|
properties.visibility = styles.visibility;
|
|
|
|
|
delete styles.visibility;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (styles?.disabledState) {
|
|
|
|
|
properties.disabledState = styles.disabledState
|
|
|
|
|
delete styles.disabledState
|
|
|
|
|
}
|
2025-07-13 11:17:41 +00:00
|
|
|
|
2025-07-15 15:37:46 +00:00
|
|
|
if (general?.tooltip) {
|
|
|
|
|
properties.tooltip = general?.tooltip;
|
|
|
|
|
delete general?.tooltip;
|
|
|
|
|
}
|
2025-07-13 11:17:41 +00:00
|
|
|
|
2025-07-15 15:37:46 +00:00
|
|
|
if (generalStyles?.boxShadow) {
|
|
|
|
|
styles.boxShadow = generalStyles?.boxShadow;
|
|
|
|
|
delete generalStyles?.boxShadow;
|
|
|
|
|
}
|
2025-07-13 11:17:41 +00:00
|
|
|
|
2025-07-15 15:37:46 +00:00
|
|
|
// Update showHeader property to false for old instances
|
|
|
|
|
if (!properties.showHeader) {
|
|
|
|
|
properties.showHeader = { value: '{{false}}' };
|
2025-07-13 11:17:41 +00:00
|
|
|
}
|
2025-07-15 15:37:46 +00:00
|
|
|
|
|
|
|
|
// Update showFooter property to false for old instances
|
|
|
|
|
if (!properties.showFooter) {
|
|
|
|
|
properties.showFooter = { value: '{{false}}' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await entityManager.update(Component, component.id, {
|
|
|
|
|
properties,
|
|
|
|
|
styles,
|
|
|
|
|
general,
|
|
|
|
|
generalStyles,
|
|
|
|
|
});
|
2025-07-13 11:17:41 +00:00
|
|
|
}
|
2025-07-15 15:37:46 +00:00
|
|
|
}
|
2025-07-13 11:17:41 +00:00
|
|
|
|
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|