From 4441ed51169e8be930c548b17f54147ff6bd8e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 15 Nov 2023 10:31:08 +0100 Subject: [PATCH] fix(core): Fix named parameter resolution in migrations (#7688) Fixes #7628 --- .../1620821879465-UniqueWorkflowNames.ts | 9 +++--- ...1630330987096-UpdateWorkflowCredentials.ts | 30 ++++++++----------- .../common/1658930531669-AddNodeIds.ts | 18 +++++------ ...669739707124-AddWorkflowVersionIdColumn.ts | 9 +++--- ...0580449-PurgeInvalidWorkflowConnections.ts | 9 +++--- packages/cli/src/databases/types.ts | 6 +--- .../src/databases/utils/migrationHelpers.ts | 12 +++----- 7 files changed, 37 insertions(+), 56 deletions(-) diff --git a/packages/cli/src/databases/migrations/common/1620821879465-UniqueWorkflowNames.ts b/packages/cli/src/databases/migrations/common/1620821879465-UniqueWorkflowNames.ts index 61569b6cdf..15a8063ef4 100644 --- a/packages/cli/src/databases/migrations/common/1620821879465-UniqueWorkflowNames.ts +++ b/packages/cli/src/databases/migrations/common/1620821879465-UniqueWorkflowNames.ts @@ -20,11 +20,10 @@ export class UniqueWorkflowNames1620821879465 implements ReversibleMigration { await Promise.all( duplicates.map(async (workflow, index) => { if (index === 0) return; - return runQuery( - `UPDATE ${tableName} SET name = :name WHERE id = :id`, - { name: `${workflow.name} ${index + 1}` }, - { id: workflow.id }, - ); + return runQuery(`UPDATE ${tableName} SET name = :name WHERE id = :id`, { + name: `${workflow.name} ${index + 1}`, + id: workflow.id, + }); }), ); } diff --git a/packages/cli/src/databases/migrations/common/1630330987096-UpdateWorkflowCredentials.ts b/packages/cli/src/databases/migrations/common/1630330987096-UpdateWorkflowCredentials.ts index 2a189cd06b..e8de8dd9fc 100644 --- a/packages/cli/src/databases/migrations/common/1630330987096-UpdateWorkflowCredentials.ts +++ b/packages/cli/src/databases/migrations/common/1630330987096-UpdateWorkflowCredentials.ts @@ -42,11 +42,10 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati } }); if (credentialsUpdated) { - await runQuery( - `UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, - { nodes: JSON.stringify(nodes) }, - { id: workflow.id }, - ); + await runQuery(`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, { + nodes: JSON.stringify(nodes), + id: workflow.id, + }); } }); }); @@ -79,8 +78,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati await runQuery( `UPDATE ${executionsTable} SET ${escape.columnName('workflowData')} = :data WHERE id = :id`, - { data: JSON.stringify(workflowData) }, - { id: execution.id }, + { data: JSON.stringify(workflowData), id: execution.id }, ); } }); @@ -114,8 +112,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati await runQuery( `UPDATE ${executionsTable} SET ${escape.columnName('workflowData')} = :data WHERE id = :id`, - { data: JSON.stringify(workflowData) }, - { id: execution.id }, + { data: JSON.stringify(workflowData), id: execution.id }, ); } }); @@ -160,11 +157,10 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati } }); if (credentialsUpdated) { - await runQuery( - `UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, - { nodes: JSON.stringify(nodes) }, - { id: workflow.id }, - ); + await runQuery(`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, { + nodes: JSON.stringify(nodes), + id: workflow.id, + }); } }); }); @@ -206,8 +202,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati await runQuery( `UPDATE ${executionsTable} SET ${escape.columnName('workflowData')} = :data WHERE id = :id`, - { data: JSON.stringify(workflowData) }, - { id: execution.id }, + { data: JSON.stringify(workflowData), id: execution.id }, ); } }); @@ -249,8 +244,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati await runQuery( `UPDATE ${executionsTable} SET ${escape.columnName('workflowData')} = :data WHERE id = :id`, - { data: JSON.stringify(workflowData) }, - { id: execution.id }, + { data: JSON.stringify(workflowData), id: execution.id }, ); } }); diff --git a/packages/cli/src/databases/migrations/common/1658930531669-AddNodeIds.ts b/packages/cli/src/databases/migrations/common/1658930531669-AddNodeIds.ts index d67da73990..84f1218e98 100644 --- a/packages/cli/src/databases/migrations/common/1658930531669-AddNodeIds.ts +++ b/packages/cli/src/databases/migrations/common/1658930531669-AddNodeIds.ts @@ -18,11 +18,10 @@ export class AddNodeIds1658930531669 implements ReversibleMigration { } }); - await runQuery( - `UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, - { nodes: JSON.stringify(nodes) }, - { id: workflow.id }, - ); + await runQuery(`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, { + nodes: JSON.stringify(nodes), + id: workflow.id, + }); }); }); } @@ -33,11 +32,10 @@ export class AddNodeIds1658930531669 implements ReversibleMigration { await runInBatches(workflowsQuery, async (workflows) => { workflows.forEach(async (workflow) => { const nodes = parseJson(workflow.nodes).map(({ id, ...rest }) => rest); - await runQuery( - `UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, - { nodes: JSON.stringify(nodes) }, - { id: workflow.id }, - ); + await runQuery(`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, { + nodes: JSON.stringify(nodes), + id: workflow.id, + }); }); }); } diff --git a/packages/cli/src/databases/migrations/common/1669739707124-AddWorkflowVersionIdColumn.ts b/packages/cli/src/databases/migrations/common/1669739707124-AddWorkflowVersionIdColumn.ts index 12f4a0e06f..004af7d2df 100644 --- a/packages/cli/src/databases/migrations/common/1669739707124-AddWorkflowVersionIdColumn.ts +++ b/packages/cli/src/databases/migrations/common/1669739707124-AddWorkflowVersionIdColumn.ts @@ -12,11 +12,10 @@ export class AddWorkflowVersionIdColumn1669739707124 implements ReversibleMigrat const workflowIds: Workflow[] = await runQuery(`SELECT id FROM ${tableName}`); for (const { id } of workflowIds) { - await runQuery( - `UPDATE ${tableName} SET ${columnName} = :versionId WHERE id = :id`, - { versionId: uuidv4() }, - { id }, - ); + await runQuery(`UPDATE ${tableName} SET ${columnName} = :versionId WHERE id = :id`, { + versionId: uuidv4(), + id, + }); } } diff --git a/packages/cli/src/databases/migrations/common/1675940580449-PurgeInvalidWorkflowConnections.ts b/packages/cli/src/databases/migrations/common/1675940580449-PurgeInvalidWorkflowConnections.ts index 44f7fe4689..a15c873d36 100644 --- a/packages/cli/src/databases/migrations/common/1675940580449-PurgeInvalidWorkflowConnections.ts +++ b/packages/cli/src/databases/migrations/common/1675940580449-PurgeInvalidWorkflowConnections.ts @@ -47,11 +47,10 @@ export class PurgeInvalidWorkflowConnections1675940580449 implements Irreversibl }); // Update database with new connections - return runQuery( - `UPDATE ${workflowsTable} SET connections = :connections WHERE id = :id`, - { connections: JSON.stringify(connections) }, - { id: workflow.id }, - ); + return runQuery(`UPDATE ${workflowsTable} SET connections = :connections WHERE id = :id`, { + connections: JSON.stringify(connections), + id: workflow.id, + }); }), ); } diff --git a/packages/cli/src/databases/types.ts b/packages/cli/src/databases/types.ts index f04deeceba..9574e5f201 100644 --- a/packages/cli/src/databases/types.ts +++ b/packages/cli/src/databases/types.ts @@ -22,11 +22,7 @@ export interface MigrationContext { tableName(name: string): string; indexName(name: string): string; }; - runQuery( - sql: string, - unsafeParameters?: ObjectLiteral, - nativeParameters?: ObjectLiteral, - ): Promise; + runQuery(sql: string, namedParameters?: ObjectLiteral): Promise; runInBatches( query: string, operation: (results: T[]) => Promise, diff --git a/packages/cli/src/databases/utils/migrationHelpers.ts b/packages/cli/src/databases/utils/migrationHelpers.ts index d2e1d0bba0..329cfa9b9c 100644 --- a/packages/cli/src/databases/utils/migrationHelpers.ts +++ b/packages/cli/src/databases/utils/migrationHelpers.ts @@ -110,16 +110,12 @@ const createContext = (queryRunner: QueryRunner, migration: Migration): Migratio tableName: (name) => queryRunner.connection.driver.escape(`${tablePrefix}${name}`), indexName: (name) => queryRunner.connection.driver.escape(`IDX_${tablePrefix}${name}`), }, - runQuery: async ( - sql: string, - unsafeParameters?: ObjectLiteral, - safeParameters?: ObjectLiteral, - ) => { - if (unsafeParameters) { + runQuery: async (sql: string, namedParameters?: ObjectLiteral) => { + if (namedParameters) { const [query, parameters] = queryRunner.connection.driver.escapeQueryWithParameters( sql, - unsafeParameters, - safeParameters ?? {}, + namedParameters, + {}, ); return queryRunner.query(query, parameters) as Promise; } else {