ToolJet/server/data-migrations/1769163530336-MigrateVisibilityDisabledStatesForIFrame.ts
Shaurya Sharma 6d4948b988
Added iframe URL, isLoading, isDisabled, isVisibile exposed variables states along with CSA (#15075)
* Added URL, isLoading, isDisabled, isVisible exposed variables along with CSAs

* Added migration for visibility, disabledState, tooltip, boxShadow and loading State

* Added component to import export logic
2026-01-27 18:22:14 +05:30

78 lines
2.4 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
export class MigrateVisibilityDisabledStatesForIFrame1769163530336 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const batchSize = 100;
let offset = 0;
let hasMoreData = true;
while (hasMoreData) {
// Fetch components in batches using raw SQL
const components = await queryRunner.query(
`SELECT id, properties, styles, general_properties, general_styles
FROM components
WHERE type = 'IFrame'
ORDER BY "created_at" ASC
LIMIT $1 OFFSET $2`,
[batchSize, offset]
);
if (components.length === 0) {
hasMoreData = false;
break;
}
await this.processUpdates(queryRunner, components);
offset += batchSize;
}
}
private async processUpdates(queryRunner: QueryRunner, components: any[]) {
for (const component of components) {
const properties = component.properties ? { ...component.properties } : {};
const styles = component.styles ? { ...component.styles } : {};
const general = component.general_properties ? { ...component.general_properties } : {};
const generalStyles = component.general_styles ? { ...component.general_styles } : {};
if (styles.visibility) {
properties.visibility = styles.visibility;
delete styles.visibility;
}
if (styles.disabledState) {
properties.disabledState = styles.disabledState;
delete styles.disabledState;
}
if (general?.tooltip) {
properties.tooltip = general?.tooltip;
delete general?.tooltip;
}
if (generalStyles?.boxShadow) {
styles.boxShadow = generalStyles?.boxShadow;
delete generalStyles?.boxShadow;
}
if (!properties.loadingState) {
properties.loadingState = { value: '{{false}}' };
}
await queryRunner.query(
`UPDATE components
SET properties = $1, styles = $2, general_properties = $3, general_styles = $4
WHERE id = $5`,
[
JSON.stringify(properties),
JSON.stringify(styles),
JSON.stringify(general),
JSON.stringify(generalStyles),
component.id,
]
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}