From a992a2da75ff3749f00c392ec3ce700b2d8535b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Mon, 31 May 2021 19:14:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=F0=9F=90=98=20Fix=20escaping=20wor?= =?UTF-8?q?kflow=20name=20dedup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1620826335440-UniqueWorkflowNames.ts | 20 +++++++++--------- .../1620824779533-UniqueWorkflowNames.ts | 21 +++++++++---------- .../1620821879465-UniqueWorkflowNames.ts | 20 +++++++++--------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/packages/cli/src/databases/mysqldb/migrations/1620826335440-UniqueWorkflowNames.ts b/packages/cli/src/databases/mysqldb/migrations/1620826335440-UniqueWorkflowNames.ts index defe831fd3..3dcf379028 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1620826335440-UniqueWorkflowNames.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1620826335440-UniqueWorkflowNames.ts @@ -13,27 +13,27 @@ export class UniqueWorkflowNames1620826335440 implements MigrationInterface { `); for (const { name } of workflowNames) { - - const duplicates = await queryRunner.query(` + const [duplicatesQuery, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(` SELECT id, name FROM ${tablePrefix}workflow_entity - WHERE name = '${name}' + WHERE name = :name ORDER BY createdAt ASC - `); + `, { name }, {}); + + const duplicates = await queryRunner.query(duplicatesQuery, parameters); if (duplicates.length > 1) { - await Promise.all(duplicates.map(({ id, name }: { id: number; name: string; }, index: number) => { if (index === 0) return Promise.resolve(); - return queryRunner.query(` + const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(` UPDATE ${tablePrefix}workflow_entity - SET name = '${name} ${index + 1}' + SET name = :name WHERE id = '${id}' - `); + `, { name: `${name} ${index + 1}`}, {}); + + return queryRunner.query(updateQuery, updateParams); })); - } - } await queryRunner.query('ALTER TABLE `' + tablePrefix + 'workflow_entity` ADD UNIQUE INDEX `IDX_' + tablePrefix + '943d8f922be094eb507cb9a7f9` (`name`)'); diff --git a/packages/cli/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.ts b/packages/cli/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.ts index 8c12e24003..ab6adb2995 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1620824779533-UniqueWorkflowNames.ts @@ -12,34 +12,33 @@ export class UniqueWorkflowNames1620824779533 implements MigrationInterface { tablePrefix = schema + '.' + tablePrefix; } - const workflowNames = await queryRunner.query(` SELECT name FROM ${tablePrefix}workflow_entity `); for (const { name } of workflowNames) { - - const duplicates = await queryRunner.query(` + const [duplicatesQuery, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(` SELECT id, name FROM ${tablePrefix}workflow_entity - WHERE name = '${name}' + WHERE name = :name ORDER BY "createdAt" ASC - `); + `, { name }, {}); + + const duplicates = await queryRunner.query(duplicatesQuery, parameters); if (duplicates.length > 1) { - await Promise.all(duplicates.map(({ id, name }: { id: number; name: string; }, index: number) => { if (index === 0) return Promise.resolve(); - return queryRunner.query(` + const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(` UPDATE ${tablePrefix}workflow_entity - SET name = '${name} ${index + 1}' + SET name = :name WHERE id = '${id}' - `); + `, { name: `${name} ${index + 1}`}, {}); + + return queryRunner.query(updateQuery, updateParams); })); - } - } await queryRunner.query(`CREATE UNIQUE INDEX "IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab" ON ${tablePrefix}workflow_entity ("name") `); diff --git a/packages/cli/src/databases/sqlite/migrations/1620821879465-UniqueWorkflowNames.ts b/packages/cli/src/databases/sqlite/migrations/1620821879465-UniqueWorkflowNames.ts index 2f38cf35bd..732b080ed0 100644 --- a/packages/cli/src/databases/sqlite/migrations/1620821879465-UniqueWorkflowNames.ts +++ b/packages/cli/src/databases/sqlite/migrations/1620821879465-UniqueWorkflowNames.ts @@ -13,27 +13,27 @@ export class UniqueWorkflowNames1620821879465 implements MigrationInterface { `); for (const { name } of workflowNames) { - - const duplicates = await queryRunner.query(` + const [duplicatesQuery, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(` SELECT id, name FROM "${tablePrefix}workflow_entity" - WHERE name = "${name}" + WHERE name = :name ORDER BY createdAt ASC - `); + `, { name }, {}); + + const duplicates = await queryRunner.query(duplicatesQuery, parameters); if (duplicates.length > 1) { - await Promise.all(duplicates.map(({ id, name }: { id: number; name: string; }, index: number) => { if (index === 0) return Promise.resolve(); - return queryRunner.query(` + const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(` UPDATE "${tablePrefix}workflow_entity" - SET name = "${name} ${index + 1}" + SET name = :name WHERE id = '${id}' - `); + `, { name: `${name} ${index + 1}`}, {}); + + return queryRunner.query(updateQuery, updateParams); })); - } - } await queryRunner.query(`CREATE UNIQUE INDEX "IDX_${tablePrefix}943d8f922be094eb507cb9a7f9" ON "${tablePrefix}workflow_entity" ("name") `);