ToolJet/server/data-migrations/1764930484535-UpdateShowFlagForCurrencyInput.ts
Rupaak Srinivas c0884b8b45
feat: add show currency flag option (#14690)
* feat: add show currency flag option

* update server config

* migrate showFlag variable

* update import export service

* fix import export service
2025-12-19 14:26:24 +05:30

53 lines
1.3 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateShowFlagForCurrencyInput1764930484535
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
const batchSize = 100;
let offset = 0;
let hasMoreData = true;
while (hasMoreData) {
const components = await queryRunner.query(
`SELECT id, properties
FROM components
WHERE type = 'CurrencyInput'
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 }
: {};
if (properties.showFlag === undefined) {
properties.showFlag = {
value: true,
};
}
await queryRunner.query(
`UPDATE components
SET properties = $1
WHERE id = $2`,
[properties, component.id]
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}