From 535dfe08384fdd0a4ea86521e917b28f7091ff82 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sun, 13 Mar 2022 05:47:19 -0400 Subject: [PATCH] fix: Fix issue with long credential type names (#2961) * :bug: Fix issue when saving long credential's types The column type in the entity credentials was varchar(33) but nodes like Google Cloud Natural Language exceed the type length. The issue in only found when using Postgres. Mysql works fine as the column type has the proper length. Probably a migration at some point did not property update the column. https://community.n8n.io/t/google-cloud-natural-language-credentials-error-too-long-value/12003/4 * :shirt: Fix lint issue * :zap: Improvement --- .../src/databases/entities/CredentialsEntity.ts | 4 ++-- .../1646834195327-IncreaseTypeVarcharLimit.ts | 17 +++++++++++++++++ .../databases/postgresdb/migrations/index.ts | 2 ++ .../1588102412422-InitialMigration.ts | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.ts diff --git a/packages/cli/src/databases/entities/CredentialsEntity.ts b/packages/cli/src/databases/entities/CredentialsEntity.ts index 50b6f168e6676..9ea39eff25c7a 100644 --- a/packages/cli/src/databases/entities/CredentialsEntity.ts +++ b/packages/cli/src/databases/entities/CredentialsEntity.ts @@ -37,7 +37,7 @@ function getTimestampSyntax() { const dbType = config.get('database.type') as DatabaseType; const map: { [key in DatabaseType]: string } = { - sqlite: "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')", + sqlite: `STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')`, postgresdb: 'CURRENT_TIMESTAMP(3)', mysqldb: 'CURRENT_TIMESTAMP(3)', mariadb: 'CURRENT_TIMESTAMP(3)', @@ -61,7 +61,7 @@ export class CredentialsEntity implements ICredentialsDb { @Index() @Column({ - length: 32, + length: 128, }) type: string; diff --git a/packages/cli/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.ts b/packages/cli/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.ts new file mode 100644 index 0000000000000..3e3250e661613 --- /dev/null +++ b/packages/cli/src/databases/postgresdb/migrations/1646834195327-IncreaseTypeVarcharLimit.ts @@ -0,0 +1,17 @@ +import { + MigrationInterface, + QueryRunner, +} from 'typeorm'; + +import config = require('../../../../config'); + +export class IncreaseTypeVarcharLimit1646834195327 implements MigrationInterface { + name = 'IncreaseTypeVarcharLimit1646834195327'; + + async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + await queryRunner.query(`ALTER TABLE ${tablePrefix}credentials_entity ALTER COLUMN "type" TYPE VARCHAR(128)`); + } + + async down(queryRunner: QueryRunner): Promise {} +} diff --git a/packages/cli/src/databases/postgresdb/migrations/index.ts b/packages/cli/src/databases/postgresdb/migrations/index.ts index d930d3f9d7edf..c1aaac39fa08c 100644 --- a/packages/cli/src/databases/postgresdb/migrations/index.ts +++ b/packages/cli/src/databases/postgresdb/migrations/index.ts @@ -8,6 +8,7 @@ import { UniqueWorkflowNames1620824779533 } from './1620824779533-UniqueWorkflow import { AddwaitTill1626176912946 } from './1626176912946-AddwaitTill'; import { UpdateWorkflowCredentials1630419189837 } from './1630419189837-UpdateWorkflowCredentials'; import { AddExecutionEntityIndexes1644422880309 } from './1644422880309-AddExecutionEntityIndexes'; +import { IncreaseTypeVarcharLimit1646834195327 } from './1646834195327-IncreaseTypeVarcharLimit'; export const postgresMigrations = [ InitialMigration1587669153312, @@ -20,4 +21,5 @@ export const postgresMigrations = [ AddwaitTill1626176912946, UpdateWorkflowCredentials1630419189837, AddExecutionEntityIndexes1644422880309, + IncreaseTypeVarcharLimit1646834195327, ]; diff --git a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts index 09a0da911ae90..321560fc90099 100644 --- a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts +++ b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts @@ -11,7 +11,7 @@ export class InitialMigration1588102412422 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query(`CREATE TABLE IF NOT EXISTS "${tablePrefix}credentials_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "data" text NOT NULL, "type" varchar(32) NOT NULL, "nodesAccess" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL)`, undefined); + await queryRunner.query(`CREATE TABLE IF NOT EXISTS "${tablePrefix}credentials_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(128) NOT NULL, "data" text NOT NULL, "type" varchar(128) NOT NULL, "nodesAccess" text NOT NULL, "createdAt" datetime NOT NULL, "updatedAt" datetime NOT NULL)`, undefined); await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_${tablePrefix}07fde106c0b471d8cc80a64fc8" ON "${tablePrefix}credentials_entity" ("type") `, undefined); await queryRunner.query(`CREATE TABLE IF NOT EXISTS "${tablePrefix}execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime NOT NULL, "workflowData" text NOT NULL, "workflowId" varchar)`, undefined); await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_${tablePrefix}c4d999a5e90784e8caccf5589d" ON "${tablePrefix}execution_entity" ("workflowId") `, undefined);