mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
* salesforce & snowflake changes added to prerelease * module import error fixes * optional parameter for getAuthUrl method
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
|
import { MigrationProgress, processDataInBatches } from '@helpers/migration.helper';
|
|
import { dbTransactionWrap } from '@helpers/database.helper';
|
|
|
|
export class UpdateSalesforceSourceOptions1751280222525 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
const entityManager = queryRunner.manager;
|
|
const totalRecords = await entityManager.query(
|
|
`
|
|
SELECT COUNT(*)
|
|
FROM data_source_options dso
|
|
JOIN data_sources ds ON dso.data_source_id = ds.id
|
|
WHERE ds.kind = $1
|
|
|
|
`,
|
|
['salesforce']
|
|
);
|
|
const totalCount = parseInt(totalRecords[0].count);
|
|
if (totalCount === 0) {
|
|
console.log('No records found to update for Salesforce data sources.');
|
|
return;
|
|
}
|
|
await this.updateSalesforceUserConfig(entityManager, totalCount);
|
|
}
|
|
|
|
private async updateSalesforceUserConfig(entityManager: EntityManager, totalCount: number): Promise<void> {
|
|
return dbTransactionWrap(async (entityManager: EntityManager) => {
|
|
const migrationProgress = new MigrationProgress('UpdateSalesforceSourceOptions1751280222525', totalCount);
|
|
const batchSize = 100;
|
|
|
|
const fetchDataSourceOptionsInBatches = async (entityManager: EntityManager, skip: number, take: number) => {
|
|
return await entityManager.query(
|
|
`
|
|
SELECT dso.id, dso.options, ds.name, dso.environment_id
|
|
FROM data_source_options dso
|
|
JOIN data_sources ds ON dso.data_source_id = ds.id
|
|
WHERE ds.kind = $1
|
|
ORDER BY dso.id
|
|
LIMIT $2 OFFSET $3
|
|
`,
|
|
['salesforce', take, skip]
|
|
);
|
|
};
|
|
|
|
const processDataSourceOptionsBatch = async (entityManager: EntityManager, dataSourceOptions: any[]) => {
|
|
for (const dataSourceOption of dataSourceOptions) {
|
|
const options = dataSourceOption.options;
|
|
if (options) {
|
|
options.auth_type = { value: 'oauth2', encrypted: false };
|
|
options.grant_type = { value: 'authorization_code', encrypted: false };
|
|
options.scopes = { value: 'full', encrypted: false };
|
|
options.oauth_type = { value: 'custom_app', encrypted: false };
|
|
|
|
options.client_auth = { value: 'body', encrypted: false };
|
|
await entityManager.query(
|
|
`
|
|
UPDATE data_source_options
|
|
SET options = $1
|
|
WHERE id = $2
|
|
`,
|
|
[options, dataSourceOption.id]
|
|
);
|
|
}
|
|
migrationProgress.show();
|
|
}
|
|
};
|
|
|
|
await processDataInBatches(
|
|
entityManager,
|
|
fetchDataSourceOptionsInBatches,
|
|
processDataSourceOptionsBatch,
|
|
batchSize
|
|
);
|
|
}, entityManager);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
}
|