Skip to content

Commit

Permalink
fix: Fix issue with long credential type names (#2961)
Browse files Browse the repository at this point in the history
* 🐛 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

* 👕 Fix lint issue

* ⚡ Improvement
  • Loading branch information
RicardoE105 authored Mar 13, 2022
1 parent 2d8ac4b commit 535dfe0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/CredentialsEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -61,7 +61,7 @@ export class CredentialsEntity implements ICredentialsDb {

@Index()
@Column({
length: 32,
length: 128,
})
type: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/postgresdb/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,4 +21,5 @@ export const postgresMigrations = [
AddwaitTill1626176912946,
UpdateWorkflowCredentials1630419189837,
AddExecutionEntityIndexes1644422880309,
IncreaseTypeVarcharLimit1646834195327,
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InitialMigration1588102412422 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
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);
Expand Down

0 comments on commit 535dfe0

Please sign in to comment.