mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
separate migrations
This commit is contained in:
parent
f6571d92a3
commit
574a4eaf1d
3 changed files with 140 additions and 70 deletions
|
|
@ -1,70 +0,0 @@
|
|||
import { Component } from '@entities/component.entity';
|
||||
import { processDataInBatches } from '@helpers/migration.helper';
|
||||
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class MoveVisibilityDisabledStatesDividerLink1743053824028 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const componentTypes = ['Container', '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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 (properties.showHeader == undefined || null) {
|
||||
properties.showHeader = false;
|
||||
}
|
||||
|
||||
if (component.type === 'Form' && properties.showFooter == undefined || null) {
|
||||
properties.showFooter = false;
|
||||
}
|
||||
|
||||
if (styles.visibility) {
|
||||
properties.visibility = styles.visibility;
|
||||
delete styles.visibility;
|
||||
}
|
||||
|
||||
if (component.type === 'Form' && general?.tooltip) {
|
||||
properties.tooltip = general?.tooltip;
|
||||
delete general?.tooltip;
|
||||
}
|
||||
|
||||
if (generalStyles?.boxShadow) {
|
||||
styles.boxShadow = generalStyles?.boxShadow;
|
||||
delete generalStyles?.boxShadow;
|
||||
}
|
||||
|
||||
await entityManager.update(Component, component.id, {
|
||||
properties,
|
||||
styles,
|
||||
general,
|
||||
generalStyles,
|
||||
});
|
||||
}
|
||||
}
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
import { Component } from '@entities/component.entity';
|
||||
import { processDataInBatches } from '@helpers/migration.helper';
|
||||
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
||||
export class MigrateFormVisibilityHeaderFooterProperties1752403387878 implements MigrationInterface {
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if (general?.tooltip) {
|
||||
properties.tooltip = general?.tooltip;
|
||||
delete general?.tooltip;
|
||||
}
|
||||
|
||||
if (generalStyles?.boxShadow) {
|
||||
styles.boxShadow = generalStyles?.boxShadow;
|
||||
delete generalStyles?.boxShadow;
|
||||
}
|
||||
|
||||
// Update showHeader property to false for old instances
|
||||
if (!properties.showHeader) {
|
||||
properties.showHeader = { value: '{{false}}' };
|
||||
}
|
||||
|
||||
// Update showHeader property to false for old instances
|
||||
if (!properties.showFooter) {
|
||||
properties.showHeader = { value: '{{false}}' };
|
||||
}
|
||||
|
||||
await entityManager.update(Component, component.id, {
|
||||
properties,
|
||||
styles,
|
||||
general,
|
||||
generalStyles,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
import { Component } from '@entities/component.entity';
|
||||
import { processDataInBatches } from '@helpers/migration.helper';
|
||||
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class MigrateContainerVisibilityProperties1752404494845 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const componentTypes = ['Container'];
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if (generalStyles?.boxShadow) {
|
||||
styles.boxShadow = generalStyles?.boxShadow;
|
||||
delete generalStyles?.boxShadow;
|
||||
}
|
||||
|
||||
await entityManager.update(Component, component.id, {
|
||||
properties,
|
||||
styles,
|
||||
general,
|
||||
generalStyles,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue