mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
🐛 Fix escaping workflow name dedup (#1850)
This commit is contained in:
parent
8f6344fbd5
commit
65fae11f24
|
@ -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`)');
|
||||
|
|
|
@ -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") `);
|
||||
|
|
|
@ -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") `);
|
||||
|
|
Loading…
Reference in a new issue