UNPKG

n8n

Version:

n8n Workflow Automation Tool

54 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UniqueWorkflowNames1620824779533 = void 0; const config = require("../../../../config"); class UniqueWorkflowNames1620824779533 { constructor() { this.name = 'UniqueWorkflowNames1620824779533'; } async up(queryRunner) { let tablePrefix = config.get('database.tablePrefix'); const tablePrefixPure = tablePrefix; const schema = config.get('database.postgresdb.schema'); if (schema) { tablePrefix = schema + '.' + tablePrefix; } const workflowNames = await queryRunner.query(` SELECT name FROM ${tablePrefix}workflow_entity `); for (const { name } of workflowNames) { const [duplicatesQuery, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(` SELECT id, name FROM ${tablePrefix}workflow_entity 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 }, index) => { if (index === 0) return Promise.resolve(); const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(` UPDATE ${tablePrefix}workflow_entity 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") `); } async down(queryRunner) { let tablePrefix = config.get('database.tablePrefix'); const tablePrefixPure = tablePrefix; const schema = config.get('database.postgresdb.schema'); if (schema) { tablePrefix = schema + '.' + tablePrefix; } await queryRunner.query(`DROP INDEX "public"."IDX_${tablePrefixPure}a252c527c4c89237221fe2c0ab"`); } } exports.UniqueWorkflowNames1620824779533 = UniqueWorkflowNames1620824779533; //# sourceMappingURL=1620824779533-UniqueWorkflowNames.js.map