import { MigrationInterface, QueryRunner } from 'typeorm'; export class MigrateVisibilityDisabledStatesForIFrame1769163530336 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { 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 {} }