mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 13:37:28 +00:00
Hotfix - backfill for runpy quries v1 (#5577)
* creates a new runpy data source and attaches all such queries to it * clean up * clean up
This commit is contained in:
parent
e93172d9da
commit
10f81fa366
2 changed files with 55 additions and 3 deletions
|
|
@ -49,8 +49,8 @@ export class BackfillDataSources1667076251897 implements MigrationInterface {
|
|||
}
|
||||
|
||||
async createDefaultVersionAndAttachQueries(entityManager: EntityManager, version: any) {
|
||||
let runjsDS, restapiDS;
|
||||
for (const kind of ['runjs', 'restapi']) {
|
||||
let runjsDS, restapiDS, runpyDS;
|
||||
for (const kind of ['runjs', 'restapi', 'runpy']) {
|
||||
const dataSourceResult = await entityManager.query(
|
||||
'insert into data_sources (name, kind, app_version_id, app_id, type) values ($1, $2, $3, $4, $5) returning "id"',
|
||||
[`${kind}default`, kind, version.id, version.app_id, 'static']
|
||||
|
|
@ -58,6 +58,8 @@ export class BackfillDataSources1667076251897 implements MigrationInterface {
|
|||
|
||||
if (kind === 'runjs') {
|
||||
runjsDS = dataSourceResult[0].id;
|
||||
} else if (kind === 'runpy') {
|
||||
runpyDS = dataSourceResult[0].id;
|
||||
} else {
|
||||
restapiDS = dataSourceResult[0].id;
|
||||
}
|
||||
|
|
@ -72,7 +74,7 @@ export class BackfillDataSources1667076251897 implements MigrationInterface {
|
|||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.update(DataQuery)
|
||||
.set({ dataSourceId: dataQuery.kind === 'runjs' ? runjsDS : restapiDS })
|
||||
.set({ dataSourceId: dataQuery.kind === 'runjs' ? runjsDS : dataQuery.kind === 'runpy' ? runpyDS : restapiDS })
|
||||
.where({ id: dataQuery.id })
|
||||
.execute();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
import { EntityManager, MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* finds all the queries which are attached to restapi datasource with type static but have a non-null code option, which indicates that they are actually associated with a runpy data source.
|
||||
* creates a new runpy data source and attaches all such queries to it.
|
||||
*/
|
||||
|
||||
export class BackfillRunpyDatasources1676545162064 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const entityManager = queryRunner.manager;
|
||||
|
||||
const allVersions = await entityManager
|
||||
.createQueryBuilder()
|
||||
.select()
|
||||
.from('app_versions', 'app_versions')
|
||||
.getRawMany();
|
||||
|
||||
for (const version of allVersions) {
|
||||
await this.createDefaultVersionAndAttachQueries(entityManager, version);
|
||||
}
|
||||
}
|
||||
|
||||
async createDefaultVersionAndAttachQueries(entityManager: EntityManager, version: any) {
|
||||
const wronglyAttachedRunpyQueries = await entityManager.query(
|
||||
"select data_queries.id from data_queries inner join data_sources on data_queries.data_source_id = data_sources.id where data_queries.options->> 'code' is not null and data_sources.kind = 'restapi' and data_sources.type = 'static' and data_sources.app_version_id = $1",
|
||||
[version.id]
|
||||
);
|
||||
|
||||
if (wronglyAttachedRunpyQueries.length > 0) {
|
||||
let runpyDS = await entityManager.query(
|
||||
"select data_sources.id from data_sources where data_sources.kind = 'runpy' and data_sources.type = 'static'"
|
||||
);
|
||||
|
||||
if (runpyDS.length === 0) {
|
||||
runpyDS = await entityManager.query(
|
||||
'insert into data_sources (name, kind, app_version_id, type) values ($1, $2, $3, $4) returning "id"',
|
||||
['runpydefault', 'runpy', version.id, 'static']
|
||||
);
|
||||
}
|
||||
await entityManager.query(
|
||||
`update data_queries set data_source_id = $1 where id in (${wronglyAttachedRunpyQueries
|
||||
.map(({ id }) => `'${id}'`)
|
||||
.join()})`,
|
||||
[runpyDS[0].id]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
||||
Loading…
Reference in a new issue