From 627d9338f1436812a61648896ba95aad4850890b Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Wed, 13 Jan 2021 20:54:59 +0100 Subject: [PATCH 01/16] :construction: add webhookId to URL --- packages/workflow/src/NodeHelpers.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 15d4d4d28c626..9ab15fea5fda1 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -641,13 +641,13 @@ export function getNodeParameters(nodePropertiesArray: INodeProperties[], nodeVa } } - // Itterate over all collections + // Iterate over all collections for (const itemName of Object.keys(propertyValues || {})) { if (nodeProperties.typeOptions !== undefined && nodeProperties.typeOptions.multipleValues === true) { // Multiple can be set so will be an array const tempArrayValue: INodeParameters[] = []; - // Itterate over all items as it contains multiple ones + // Iterate over all items as it contains multiple ones for (const nodeValue of (propertyValues as INodeParameters)[itemName] as INodeParameters[]) { nodePropertyOptions = nodeProperties!.options!.find((nodePropertyOptions) => nodePropertyOptions.name === itemName) as INodePropertyCollection; @@ -883,6 +883,10 @@ export function getNodeWebhookPath(workflowId: string, node: INode, path: string * @returns {string} */ export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string, isFullPath?: boolean): string { + if (path.includes('/:') && node.webhookId) { + // setting this to false to prefix the webhookId + isFullPath = false; + } return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path, isFullPath)}`; } From cc78ecf75a20fba13d598ef951a5c583df6d8a22 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Wed, 13 Jan 2021 20:54:59 +0100 Subject: [PATCH 02/16] :construction: add webhookId to webhook entity, :wrench: refactor migrations --- .../cli/src/databases/sqlite/WebhookEntity.ts | 5 ++++ .../1588102412422-InitialMigration.ts | 2 +- .../migrations/1592445003908-WebhookModel.ts | 2 +- .../1594825041918-CreateIndexStoppedAt.ts | 4 +-- .../migrations/1610570498276-AddWebhookId.ts | 28 +++++++++++++++++++ .../src/databases/sqlite/migrations/index.ts | 14 ++++++++-- 6 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts diff --git a/packages/cli/src/databases/sqlite/WebhookEntity.ts b/packages/cli/src/databases/sqlite/WebhookEntity.ts index a78fd34ae9878..04e2360981286 100644 --- a/packages/cli/src/databases/sqlite/WebhookEntity.ts +++ b/packages/cli/src/databases/sqlite/WebhookEntity.ts @@ -2,6 +2,7 @@ import { Column, Entity, PrimaryColumn, + Index, } from 'typeorm'; import { @@ -9,6 +10,7 @@ import { } from '../../Interfaces'; @Entity() +@Index(["webhookId", "method"], { unique: true }) export class WebhookEntity implements IWebhookDb { @Column() @@ -22,4 +24,7 @@ export class WebhookEntity implements IWebhookDb { @Column() node: string; + + @Column({ nullable: true }) + webhookId: string; } diff --git a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts index 09a0da911ae90..fe40dd66f03cf 100644 --- a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts +++ b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export class InitialMigration1588102412422 implements MigrationInterface { +export default class InitialMigration1588102412422 implements MigrationInterface { name = 'InitialMigration1588102412422'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts b/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts index b011061e28405..55db01991a3de 100644 --- a/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts +++ b/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export class WebhookModel1592445003908 implements MigrationInterface { +export default class WebhookModel1592445003908 implements MigrationInterface { name = 'WebhookModel1592445003908'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts b/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts index 596ff81d19bba..74322e416afdf 100644 --- a/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts @@ -2,13 +2,13 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export class CreateIndexStoppedAt1594825041918 implements MigrationInterface { +export default class CreateIndexStoppedAt1594825041918 implements MigrationInterface { name = 'CreateIndexStoppedAt1594825041918'; async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query(`CREATE INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1" ON "execution_entity" ("stoppedAt") `); + await queryRunner.query(`CREATE INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1" ON "${tablePrefix}execution_entity" ("stoppedAt") `); } async down(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts new file mode 100644 index 0000000000000..6879eaf9b1d63 --- /dev/null +++ b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts @@ -0,0 +1,28 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +import * as config from '../../../../config'; + +export default class AddWebhookId1610570498276 implements MigrationInterface { + name = 'AddWebhookId1610570498276' + + public async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query(`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`); + await queryRunner.query(`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`); + await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`); + await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`); + await queryRunner.query(`CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `); + } + + public async down(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`); + await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`); + await queryRunner.query(`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`); + await queryRunner.query(`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`); + await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`); + } + +} diff --git a/packages/cli/src/databases/sqlite/migrations/index.ts b/packages/cli/src/databases/sqlite/migrations/index.ts index d6a8ffad1cd29..e15a8d632f398 100644 --- a/packages/cli/src/databases/sqlite/migrations/index.ts +++ b/packages/cli/src/databases/sqlite/migrations/index.ts @@ -1,3 +1,11 @@ -export * from './1588102412422-InitialMigration'; -export * from './1592445003908-WebhookModel'; -export * from './1594825041918-CreateIndexStoppedAt'; +import InitialMigration1588102412422 from './1588102412422-InitialMigration'; +import WebhookModel1592445003908 from './1592445003908-WebhookModel'; +import CreateIndexStoppedAt1594825041918 from './1594825041918-CreateIndexStoppedAt'; +import AddWebhookId1610570498276 from './1610570498276-AddWebhookId'; + +export default [ + InitialMigration1588102412422, + WebhookModel1592445003908, + CreateIndexStoppedAt1594825041918, + AddWebhookId1610570498276, +] From a6ac644d7e7f2cd1e917f192f7bd7fa2204a7122 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Thu, 14 Jan 2021 16:18:43 +0100 Subject: [PATCH 03/16] :construction: :elephant: postgres migration --- packages/cli/src/Db.ts | 24 ++--------- .../src/databases/postgresdb/WebhookEntity.ts | 5 +++ .../1587669153312-InitialMigration.ts | 2 +- .../migrations/1589476000887-WebhookModel.ts | 2 +- .../1594828256133-CreateIndexStoppedAt.ts | 2 +- .../migrations/1610632462428-AddWebhookId.ts | 33 ++++++++++++++ .../databases/postgresdb/migrations/index.ts | 13 ++++-- .../migrations/1610570498276-AddWebhookId.ts | 43 +++++++++++-------- 8 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index f4522e52ed810..4dce5490c4d65 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -32,11 +32,7 @@ export let collections: IDatabaseCollections = { Webhook: null, }; -import { - CreateIndexStoppedAt1594828256133, - InitialMigration1587669153312, - WebhookModel1589476000887, -} from './databases/postgresdb/migrations'; +import postgresMigrations from './databases/postgresdb/migrations'; import { CreateIndexStoppedAt1594910478695, @@ -50,11 +46,7 @@ import { WebhookModel1592447867632, } from './databases/mysqldb/migrations'; -import { - CreateIndexStoppedAt1594825041918, - InitialMigration1588102412422, - WebhookModel1592445003908, -} from './databases/sqlite/migrations'; +import sqliteMigrations from './databases/sqlite/migrations'; import * as path from 'path'; @@ -112,11 +104,7 @@ export async function init(): Promise { port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number, username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string, schema: config.get('database.postgresdb.schema'), - migrations: [ - InitialMigration1587669153312, - WebhookModel1589476000887, - CreateIndexStoppedAt1594828256133, - ], + migrations: postgresMigrations, migrationsRun: true, migrationsTableName: `${entityPrefix}migrations`, ssl, @@ -151,11 +139,7 @@ export async function init(): Promise { type: 'sqlite', database: path.join(n8nFolder, 'database.sqlite'), entityPrefix, - migrations: [ - InitialMigration1588102412422, - WebhookModel1592445003908, - CreateIndexStoppedAt1594825041918, - ], + migrations: sqliteMigrations, migrationsRun: true, migrationsTableName: `${entityPrefix}migrations`, }; diff --git a/packages/cli/src/databases/postgresdb/WebhookEntity.ts b/packages/cli/src/databases/postgresdb/WebhookEntity.ts index 6e511cde74e39..db08a493075b4 100644 --- a/packages/cli/src/databases/postgresdb/WebhookEntity.ts +++ b/packages/cli/src/databases/postgresdb/WebhookEntity.ts @@ -2,6 +2,7 @@ import { Column, Entity, PrimaryColumn, + Index, } from 'typeorm'; import { @@ -9,6 +10,7 @@ import { } from '../../'; @Entity() +@Index(["webhookId", "method"], { unique: true }) export class WebhookEntity implements IWebhookDb { @Column() @@ -22,4 +24,7 @@ export class WebhookEntity implements IWebhookDb { @Column() node: string; + + @Column({ nullable: true }) + webhookId: string; } diff --git a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts index eace7a92fb732..911f236d23bb6 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts @@ -3,7 +3,7 @@ import { import * as config from '../../../../config'; -export class InitialMigration1587669153312 implements MigrationInterface { +export default class InitialMigration1587669153312 implements MigrationInterface { name = 'InitialMigration1587669153312'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts b/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts index 0c195f9d5442f..e4ae54ae0969e 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export class WebhookModel1589476000887 implements MigrationInterface { +export default class WebhookModel1589476000887 implements MigrationInterface { name = 'WebhookModel1589476000887'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts b/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts index 664834082e10e..c0c99d313a4f3 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export class CreateIndexStoppedAt1594828256133 implements MigrationInterface { +export default class CreateIndexStoppedAt1594828256133 implements MigrationInterface { name = 'CreateIndexStoppedAt1594828256133'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts b/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts new file mode 100644 index 0000000000000..2700096b88055 --- /dev/null +++ b/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts @@ -0,0 +1,33 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +import * as config from '../../../../config'; + +export default class AddWebhookId1610632462428 implements MigrationInterface { + name = 'AddWebhookId1610632462428'; + + public async up(queryRunner: QueryRunner): Promise { + let tablePrefix = config.get('database.tablePrefix'); + const tablePrefixPure = tablePrefix; + const schema = config.get('database.postgresdb.schema'); + if (schema) { + tablePrefix = schema + '.' + tablePrefix; + } + + await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity ADD "webhookId" character varying`); + await queryRunner.query( + `CREATE UNIQUE INDEX "IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814" ON ${tablePrefix}webhook_entity ("webhookId", "method") `, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + 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 IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814`); + await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity DROP COLUMN "webhookId"`); + } +} diff --git a/packages/cli/src/databases/postgresdb/migrations/index.ts b/packages/cli/src/databases/postgresdb/migrations/index.ts index 3b10537067f4a..5ac9425e53b8a 100644 --- a/packages/cli/src/databases/postgresdb/migrations/index.ts +++ b/packages/cli/src/databases/postgresdb/migrations/index.ts @@ -1,4 +1,11 @@ -export * from './1587669153312-InitialMigration'; -export * from './1589476000887-WebhookModel'; -export * from './1594828256133-CreateIndexStoppedAt'; +import InitialMigration1587669153312 from './1587669153312-InitialMigration'; +import WebhookModel1589476000887 from './1589476000887-WebhookModel'; +import CreateIndexStoppedAt1594828256133 from './1594828256133-CreateIndexStoppedAt'; +import AddWebhookId1610632462428 from './1610632462428-AddWebhookId' +export default [ + InitialMigration1587669153312, + WebhookModel1589476000887, + CreateIndexStoppedAt1594828256133, + AddWebhookId1610632462428, +] diff --git a/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts index 6879eaf9b1d63..693cdeee4f8b7 100644 --- a/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts +++ b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts @@ -1,28 +1,37 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; export default class AddWebhookId1610570498276 implements MigrationInterface { - name = 'AddWebhookId1610570498276' + name = 'AddWebhookId1610570498276'; - public async up(queryRunner: QueryRunner): Promise { + public async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query(`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`); - await queryRunner.query(`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`); - await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`); - await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`); - await queryRunner.query(`CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `); - } + await queryRunner.query( + `CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`, + ); + await queryRunner.query( + `INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`, + ); + await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`); + await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`); + await queryRunner.query( + `CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `, + ); + } - public async down(queryRunner: QueryRunner): Promise { + public async down(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`); - await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`); - await queryRunner.query(`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`); - await queryRunner.query(`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`); - await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`); - } - + await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`); + await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`); + await queryRunner.query( + `CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`, + ); + await queryRunner.query( + `INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`, + ); + await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`); + } } From ab4783d9849b024d5934e3234cb4f85de3b7b340 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Thu, 14 Jan 2021 17:26:56 +0100 Subject: [PATCH 04/16] :construction: add mySQL migration --- docker/images/n8n/README.md | 2 +- packages/cli/src/Db.ts | 27 +++---------------- .../src/databases/mysqldb/WebhookEntity.ts | 5 ++++ .../1588157391238-InitialMigration.ts | 2 +- .../migrations/1592447867632-WebhookModel.ts | 2 +- .../1594902918301-CreateIndexStoppedAt.ts | 2 +- .../migrations/1610640521099-AddWebhookId.ts | 23 ++++++++++++++++ .../src/databases/mysqldb/migrations/index.ts | 14 +++++++--- 8 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts diff --git a/docker/images/n8n/README.md b/docker/images/n8n/README.md index 877109ad7d2f5..b10d899325021 100644 --- a/docker/images/n8n/README.md +++ b/docker/images/n8n/README.md @@ -110,7 +110,7 @@ By default n8n uses SQLite to save credentials, past executions and workflows. n8n however also supports MongoDB, PostgresDB and MySQL. To use them simply a few environment variables have to be set. -It is important to still persist the data in the `/root/.n8` folder. The reason +It is important to still persist the data in the `/root/.n8n` folder. The reason is that it contains n8n user data. That is the name of the webhook (in case) the n8n tunnel gets used and even more important the encryption key for the credentials. If none gets found n8n creates automatically one on diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index 4dce5490c4d65..4f689a348e0db 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -33,19 +33,8 @@ export let collections: IDatabaseCollections = { }; import postgresMigrations from './databases/postgresdb/migrations'; - -import { - CreateIndexStoppedAt1594910478695, - InitialMigration1587563438936, - WebhookModel1592679094242, -} from './databases/mongodb/migrations'; - -import { - CreateIndexStoppedAt1594902918301, - InitialMigration1588157391238, - WebhookModel1592447867632, -} from './databases/mysqldb/migrations'; - +import mongodbMigrations from './databases/mongodb/migrations'; +import mysqlMigrations from './databases/mysqldb/migrations'; import sqliteMigrations from './databases/sqlite/migrations'; import * as path from 'path'; @@ -67,11 +56,7 @@ export async function init(): Promise { entityPrefix, url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string, useNewUrlParser: true, - migrations: [ - InitialMigration1587563438936, - WebhookModel1592679094242, - CreateIndexStoppedAt1594910478695, - ], + migrations: mongodbMigrations, migrationsRun: true, migrationsTableName: `${entityPrefix}migrations`, }; @@ -123,11 +108,7 @@ export async function init(): Promise { password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string, port: await GenericHelpers.getConfigValue('database.mysqldb.port') as number, username: await GenericHelpers.getConfigValue('database.mysqldb.user') as string, - migrations: [ - InitialMigration1588157391238, - WebhookModel1592447867632, - CreateIndexStoppedAt1594902918301, - ], + migrations: mysqlMigrations, migrationsRun: true, migrationsTableName: `${entityPrefix}migrations`, }; diff --git a/packages/cli/src/databases/mysqldb/WebhookEntity.ts b/packages/cli/src/databases/mysqldb/WebhookEntity.ts index a78fd34ae9878..04e2360981286 100644 --- a/packages/cli/src/databases/mysqldb/WebhookEntity.ts +++ b/packages/cli/src/databases/mysqldb/WebhookEntity.ts @@ -2,6 +2,7 @@ import { Column, Entity, PrimaryColumn, + Index, } from 'typeorm'; import { @@ -9,6 +10,7 @@ import { } from '../../Interfaces'; @Entity() +@Index(["webhookId", "method"], { unique: true }) export class WebhookEntity implements IWebhookDb { @Column() @@ -22,4 +24,7 @@ export class WebhookEntity implements IWebhookDb { @Column() node: string; + + @Column({ nullable: true }) + webhookId: string; } diff --git a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts index 1d1d4d8cc5fe5..fa788c101d4f3 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; -export class InitialMigration1588157391238 implements MigrationInterface { +export default class InitialMigration1588157391238 implements MigrationInterface { name = 'InitialMigration1588157391238'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts b/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts index 13969d72ef2b7..4fc5a365663f9 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export class WebhookModel1592447867632 implements MigrationInterface { +export default class WebhookModel1592447867632 implements MigrationInterface { name = 'WebhookModel1592447867632'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts b/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts index 24556ea6bdb73..9990e0e64be6f 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export class CreateIndexStoppedAt1594902918301 implements MigrationInterface { +export default class CreateIndexStoppedAt1594902918301 implements MigrationInterface { name = 'CreateIndexStoppedAt1594902918301'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts b/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts new file mode 100644 index 0000000000000..5723b7c738c39 --- /dev/null +++ b/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +import * as config from '../../../../config'; + +export default class AddWebhookId1610640521099 implements MigrationInterface { + name = 'AddWebhookId1610640521099'; + + public async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` ADD `webhookId` varchar(255) NULL'); + await queryRunner.query('CREATE UNIQUE INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity` (`webhookId`, `method`)'); + } + + public async down(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query( + 'DROP INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity`', + ); + await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` DROP COLUMN `webhookId`'); + } +} diff --git a/packages/cli/src/databases/mysqldb/migrations/index.ts b/packages/cli/src/databases/mysqldb/migrations/index.ts index 7c0cb217eff4d..baf42085de52f 100644 --- a/packages/cli/src/databases/mysqldb/migrations/index.ts +++ b/packages/cli/src/databases/mysqldb/migrations/index.ts @@ -1,3 +1,11 @@ -export * from './1588157391238-InitialMigration'; -export * from './1592447867632-WebhookModel'; -export * from './1594902918301-CreateIndexStoppedAt'; +import InitialMigration1588157391238 from './1588157391238-InitialMigration'; +import WebhookModel1592447867632 from './1592447867632-WebhookModel'; +import CreateIndexStoppedAt1594902918301 from './1594902918301-CreateIndexStoppedAt'; +import AddWebhookId1610640521099 from './1610640521099-AddWebhookId' + +export default [ + InitialMigration1588157391238, + WebhookModel1592447867632, + CreateIndexStoppedAt1594902918301, + AddWebhookId1610640521099, +] From abd1d0d5370019ff7fd4555c1147edddffc7d383 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Thu, 14 Jan 2021 17:27:17 +0100 Subject: [PATCH 05/16] :construction: refactor mongoDB --- packages/cli/src/databases/mongodb/WebhookEntity.ts | 5 +++++ .../151594910478695-CreateIndexStoppedAt.ts | 2 +- .../migrations/1587563438936-InitialMigration.ts | 2 +- .../mongodb/migrations/1592679094242-WebhookModel.ts | 2 +- .../cli/src/databases/mongodb/migrations/index.ts | 12 +++++++++--- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/databases/mongodb/WebhookEntity.ts b/packages/cli/src/databases/mongodb/WebhookEntity.ts index dbf90f3da1306..9f70f309d5dbf 100644 --- a/packages/cli/src/databases/mongodb/WebhookEntity.ts +++ b/packages/cli/src/databases/mongodb/WebhookEntity.ts @@ -11,6 +11,8 @@ import { } from '../../Interfaces'; @Entity() +@Index(["webhookPath", "method"], { unique: true }) +@Index(["webhookId", "method"], { unique: true }) export class WebhookEntity implements IWebhookDb { @ObjectIdColumn() @@ -27,4 +29,7 @@ export class WebhookEntity implements IWebhookDb { @Column() node: string; + + @Column() + webhookId: string; } diff --git a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts b/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts index e9cc890e8b586..2e76fcab1fd78 100644 --- a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export class CreateIndexStoppedAt1594910478695 implements MigrationInterface { +export default class CreateIndexStoppedAt1594910478695 implements MigrationInterface { name = 'CreateIndexStoppedAt1594910478695'; async up(queryRunner: MongoQueryRunner): Promise { diff --git a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts b/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts index df2785c3500ea..6956dd4e65840 100644 --- a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts +++ b/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts @@ -1,6 +1,6 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -export class InitialMigration1587563438936 implements MigrationInterface { +export default class InitialMigration1587563438936 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { } diff --git a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts b/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts index 22c4db53fa1b3..2584677548ed4 100644 --- a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts +++ b/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts @@ -8,7 +8,7 @@ import { MongoQueryRunner, } from 'typeorm/driver/mongodb/MongoQueryRunner'; -export class WebhookModel1592679094242 implements MigrationInterface { +export default class WebhookModel1592679094242 implements MigrationInterface { name = 'WebhookModel1592679094242'; async up(queryRunner: MongoQueryRunner): Promise { diff --git a/packages/cli/src/databases/mongodb/migrations/index.ts b/packages/cli/src/databases/mongodb/migrations/index.ts index ae4a6deb3876b..a8c2988120c8c 100644 --- a/packages/cli/src/databases/mongodb/migrations/index.ts +++ b/packages/cli/src/databases/mongodb/migrations/index.ts @@ -1,3 +1,9 @@ -export * from './1587563438936-InitialMigration'; -export * from './1592679094242-WebhookModel'; -export * from './151594910478695-CreateIndexStoppedAt'; +import InitialMigration1587563438936 from './1587563438936-InitialMigration'; +import WebhookModel1592679094242 from './1592679094242-WebhookModel'; +import CreateIndexStoppedAt1594910478695 from './151594910478695-CreateIndexStoppedAt'; + +export default [ + InitialMigration1587563438936, + WebhookModel1592679094242, + CreateIndexStoppedAt1594910478695, +] From 2888543dad6e11ac7df67b79ce1c441ef0fa13d5 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Thu, 14 Jan 2021 17:30:05 +0100 Subject: [PATCH 06/16] :construction: add webhookId to IWebhookDb --- packages/cli/package.json | 2 +- packages/cli/src/ActiveWorkflowRunner.ts | 4 ++++ packages/cli/src/Interfaces.ts | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 787fb7c95cf20..aba3cf5d6f1aa 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -114,7 +114,7 @@ "sqlite3": "^4.2.0", "sse-channel": "^3.1.1", "tslib": "1.11.2", - "typeorm": "^0.2.24" + "typeorm": "^0.2.30" }, "jest": { "transform": { diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index 6a955969a8588..48709c7aa4b72 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -253,6 +253,10 @@ export class ActiveWorkflowRunner { method: webhookData.httpMethod, } as IWebhookDb; + if (webhook.webhookPath.includes('/:') && node.webhookId) { + webhook.webhookId = node.webhookId; + } + try { await Db.collections.Webhook?.insert(webhook); diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 443bee653992e..4e63151c9cca7 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -57,6 +57,7 @@ export interface IWebhookDb { webhookPath: string; method: string; node: string; + webhookId?: string; } export interface IWorkflowBase extends IWorkflowBaseWorkflow { From 2eb2cae72a4445f46f1f9bb918cef71c2d1e9425 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Thu, 14 Jan 2021 23:27:45 +0100 Subject: [PATCH 07/16] :construction: starting workflow with dynamic route works --- packages/cli/src/ActiveWorkflowRunner.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index 48709c7aa4b72..25bbaa43d152f 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -116,7 +116,15 @@ export class ActiveWorkflowRunner { throw new ResponseHelper.ResponseError('The "activeWorkflows" instance did not get initialized yet.', 404, 404); } - const webhook = await Db.collections.Webhook?.findOne({ webhookPath: path, method: httpMethod }) as IWebhookDb; + let webhook = await Db.collections.Webhook?.findOne({ webhookPath: path, method: httpMethod }) as IWebhookDb; + let webhookId: string; + + if (webhook === undefined) { + const pathElements = path.split('/'); + webhookId = pathElements[0]; + webhook = await Db.collections.Webhook?.findOne({ webhookId, method: httpMethod }) as IWebhookDb; + // write params to req.params + } // check if something exist if (webhook === undefined) { @@ -124,6 +132,10 @@ export class ActiveWorkflowRunner { throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); } + if (webhookId) { + path = webhook.webhookPath; + } + const workflowData = await Db.collections.Workflow!.findOne(webhook.workflowId); if (workflowData === undefined) { throw new ResponseHelper.ResponseError(`Could not find workflow with id "${webhook.workflowId}"`, 404, 404); @@ -277,11 +289,13 @@ export class ActiveWorkflowRunner { let errorMessage = ''; // if it's a workflow from the the insert - // TODO check if there is standard error code for deplicate key violation that works + // TODO check if there is standard error code for duplicate key violation that works // with all databases if (error.name === 'MongoError' || error.name === 'QueryFailedError') { - - errorMessage = `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`; + console.log(error); + errorMessage = error.parameters.length === 5 + ? `Node [${webhook.node}] can't be saved, please duplicate [${webhook.node}] and delete the currently existing one.` + : `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`; } else if (error.detail) { // it's a error runnig the webhook methods (checkExists, create) From f5187b3af9afc26cdbe2fabb456b300ca04cf807 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 12:27:25 +0100 Subject: [PATCH 08/16] :zap: production dynamic webhooks complete --- packages/cli/src/ActiveWorkflowRunner.ts | 38 ++++++++++++------- packages/core/src/NodeExecuteFunctions.ts | 6 +++ packages/node-dev/templates/webhook/simple.ts | 3 +- packages/nodes-base/nodes/Webhook.node.ts | 9 +++-- packages/workflow/src/Interfaces.ts | 1 + packages/workflow/src/NodeHelpers.ts | 2 +- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index 25bbaa43d152f..be5b41f8085a4 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -20,6 +20,7 @@ import { } from 'n8n-core'; import { + IDataObject, IExecuteData, IGetExecutePollFunctions, IGetExecuteTriggerFunctions, @@ -117,23 +118,28 @@ export class ActiveWorkflowRunner { } let webhook = await Db.collections.Webhook?.findOne({ webhookPath: path, method: httpMethod }) as IWebhookDb; - let webhookId: string; + let webhookId: string | undefined; if (webhook === undefined) { + // check if a dynamic webhook path exists const pathElements = path.split('/'); - webhookId = pathElements[0]; + webhookId = pathElements.shift(); webhook = await Db.collections.Webhook?.findOne({ webhookId, method: httpMethod }) as IWebhookDb; - // write params to req.params - } - - // check if something exist - if (webhook === undefined) { - // The requested webhook is not registered - throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); - } - - if (webhookId) { - path = webhook.webhookPath; + if (webhook) { + path = webhook.webhookPath; + // extracting params from path + const webhookPathParams: IDataObject = {}; + webhook.webhookPath.split('/').forEach((ele, index) => { + if (ele.startsWith(':')) { + webhookPathParams[ele.slice(1)] = pathElements[index]; + } + }); + // write params to req.params + Object.assign(req.params, webhookPathParams); + } else { + // The requested webhook is not registered + throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); + } } const workflowData = await Db.collections.Workflow!.findOne(webhook.workflowId); @@ -265,10 +271,14 @@ export class ActiveWorkflowRunner { method: webhookData.httpMethod, } as IWebhookDb; - if (webhook.webhookPath.includes('/:') && node.webhookId) { + if ((path.startsWith(':') || path.includes('/:')) && node.webhookId) { webhook.webhookId = node.webhookId; } + if (webhook.webhookPath.charAt(0) === '/') { + webhook.webhookPath = webhook.webhookPath.slice(1); + } + try { await Db.collections.Webhook?.insert(webhook); diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index e6bcbd24cb41c..3ad9b2477b39e 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -993,6 +993,12 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); }, + getParamsData(): object { + if (additionalData.httpRequest === undefined) { + throw new Error('Request is missing!'); + } + return additionalData.httpRequest.params; + }, getQueryData(): object { if (additionalData.httpRequest === undefined) { throw new Error('Request is missing!'); diff --git a/packages/node-dev/templates/webhook/simple.ts b/packages/node-dev/templates/webhook/simple.ts index ab81ca51d2377..650d843178645 100644 --- a/packages/node-dev/templates/webhook/simple.ts +++ b/packages/node-dev/templates/webhook/simple.ts @@ -54,9 +54,10 @@ export class ClassNameReplace implements INodeType { const returnData: IDataObject[] = []; returnData.push( { - body: this.getBodyData(), headers: this.getHeaderData(), + params: this.getParamsData(), query: this.getQueryData(), + body: this.getBodyData(), } ); diff --git a/packages/nodes-base/nodes/Webhook.node.ts b/packages/nodes-base/nodes/Webhook.node.ts index aba5afd12fead..268a466246172 100644 --- a/packages/nodes-base/nodes/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook.node.ts @@ -412,9 +412,10 @@ export class Webhook implements INodeType { const returnItem: INodeExecutionData = { binary: {}, json: { - body: data, headers, + params: this.getParamsData(), query: this.getQueryData(), + body: data, }, }; @@ -458,9 +459,10 @@ export class Webhook implements INodeType { const returnItem: INodeExecutionData = { binary: {}, json: { - body: this.getBodyData(), headers, + params: this.getParamsData(), query: this.getQueryData(), + body: this.getBodyData(), }, }; @@ -483,9 +485,10 @@ export class Webhook implements INodeType { const response: INodeExecutionData = { json: { - body: this.getBodyData(), headers, + params: this.getParamsData(), query: this.getQueryData(), + body: this.getBodyData(), }, }; diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index fec5aa3729c15..6630a559cd7f3 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -311,6 +311,7 @@ export interface IWebhookFunctions { getNode(): INode; getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeWebhookUrl: (name: string) => string | undefined; + getParamsData(): object; getQueryData(): object; getRequestObject(): express.Request; getResponseObject(): express.Response; diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 9ab15fea5fda1..3082b5d3dd464 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -883,7 +883,7 @@ export function getNodeWebhookPath(workflowId: string, node: INode, path: string * @returns {string} */ export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string, isFullPath?: boolean): string { - if (path.includes('/:') && node.webhookId) { + if ((path.startsWith(':') || path.includes('/:')) && node.webhookId) { // setting this to false to prefix the webhookId isFullPath = false; } From c6d1d6a6b8dac560d74a5ce29a0531b9f441994b Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 12:41:59 +0100 Subject: [PATCH 09/16] :art: fix lint issues --- packages/cli/src/Db.ts | 8 ++++---- .../151594910478695-CreateIndexStoppedAt.ts | 2 +- .../migrations/1587563438936-InitialMigration.ts | 2 +- .../migrations/1592679094242-WebhookModel.ts | 2 +- .../src/databases/mongodb/migrations/index.ts | 10 +++++----- .../cli/src/databases/mysqldb/WebhookEntity.ts | 2 +- .../migrations/1588157391238-InitialMigration.ts | 2 +- .../migrations/1592447867632-WebhookModel.ts | 2 +- .../1594902918301-CreateIndexStoppedAt.ts | 2 +- .../migrations/1610640521099-AddWebhookId.ts | 8 ++++---- .../src/databases/mysqldb/migrations/index.ts | 12 ++++++------ .../src/databases/postgresdb/WebhookEntity.ts | 2 +- .../migrations/1587669153312-InitialMigration.ts | 2 +- .../migrations/1589476000887-WebhookModel.ts | 2 +- .../1594828256133-CreateIndexStoppedAt.ts | 2 +- .../migrations/1610632462428-AddWebhookId.ts | 8 ++++---- .../src/databases/postgresdb/migrations/index.ts | 12 ++++++------ .../cli/src/databases/sqlite/WebhookEntity.ts | 2 +- .../migrations/1588102412422-InitialMigration.ts | 2 +- .../migrations/1592445003908-WebhookModel.ts | 2 +- .../1594825041918-CreateIndexStoppedAt.ts | 2 +- .../migrations/1610570498276-AddWebhookId.ts | 16 ++++++++-------- .../cli/src/databases/sqlite/migrations/index.ts | 12 ++++++------ 23 files changed, 58 insertions(+), 58 deletions(-) diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index 4f689a348e0db..67565043e9bc3 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -32,10 +32,10 @@ export let collections: IDatabaseCollections = { Webhook: null, }; -import postgresMigrations from './databases/postgresdb/migrations'; -import mongodbMigrations from './databases/mongodb/migrations'; -import mysqlMigrations from './databases/mysqldb/migrations'; -import sqliteMigrations from './databases/sqlite/migrations'; +import { postgresMigrations } from './databases/postgresdb/migrations'; +import { mongodbMigrations } from './databases/mongodb/migrations'; +import { mysqlMigrations } from './databases/mysqldb/migrations'; +import { sqliteMigrations } from './databases/sqlite/migrations'; import * as path from 'path'; diff --git a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts b/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts index 2e76fcab1fd78..e9cc890e8b586 100644 --- a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export default class CreateIndexStoppedAt1594910478695 implements MigrationInterface { +export class CreateIndexStoppedAt1594910478695 implements MigrationInterface { name = 'CreateIndexStoppedAt1594910478695'; async up(queryRunner: MongoQueryRunner): Promise { diff --git a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts b/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts index 6956dd4e65840..df2785c3500ea 100644 --- a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts +++ b/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts @@ -1,6 +1,6 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -export default class InitialMigration1587563438936 implements MigrationInterface { +export class InitialMigration1587563438936 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { } diff --git a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts b/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts index 2584677548ed4..22c4db53fa1b3 100644 --- a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts +++ b/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts @@ -8,7 +8,7 @@ import { MongoQueryRunner, } from 'typeorm/driver/mongodb/MongoQueryRunner'; -export default class WebhookModel1592679094242 implements MigrationInterface { +export class WebhookModel1592679094242 implements MigrationInterface { name = 'WebhookModel1592679094242'; async up(queryRunner: MongoQueryRunner): Promise { diff --git a/packages/cli/src/databases/mongodb/migrations/index.ts b/packages/cli/src/databases/mongodb/migrations/index.ts index a8c2988120c8c..4b4239eb3db6b 100644 --- a/packages/cli/src/databases/mongodb/migrations/index.ts +++ b/packages/cli/src/databases/mongodb/migrations/index.ts @@ -1,9 +1,9 @@ -import InitialMigration1587563438936 from './1587563438936-InitialMigration'; -import WebhookModel1592679094242 from './1592679094242-WebhookModel'; -import CreateIndexStoppedAt1594910478695 from './151594910478695-CreateIndexStoppedAt'; +import { InitialMigration1587563438936 } from './1587563438936-InitialMigration'; +import { WebhookModel1592679094242 } from './1592679094242-WebhookModel'; +import { CreateIndexStoppedAt1594910478695 } from './151594910478695-CreateIndexStoppedAt'; -export default [ +export const mongodbMigrations = [ InitialMigration1587563438936, WebhookModel1592679094242, CreateIndexStoppedAt1594910478695, -] +]; diff --git a/packages/cli/src/databases/mysqldb/WebhookEntity.ts b/packages/cli/src/databases/mysqldb/WebhookEntity.ts index 04e2360981286..87beb0de03746 100644 --- a/packages/cli/src/databases/mysqldb/WebhookEntity.ts +++ b/packages/cli/src/databases/mysqldb/WebhookEntity.ts @@ -1,8 +1,8 @@ import { Column, Entity, - PrimaryColumn, Index, + PrimaryColumn, } from 'typeorm'; import { diff --git a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts index fa788c101d4f3..1d1d4d8cc5fe5 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1588157391238-InitialMigration.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; -export default class InitialMigration1588157391238 implements MigrationInterface { +export class InitialMigration1588157391238 implements MigrationInterface { name = 'InitialMigration1588157391238'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts b/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts index 4fc5a365663f9..13969d72ef2b7 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1592447867632-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export default class WebhookModel1592447867632 implements MigrationInterface { +export class WebhookModel1592447867632 implements MigrationInterface { name = 'WebhookModel1592447867632'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts b/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts index 9990e0e64be6f..24556ea6bdb73 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1594902918301-CreateIndexStoppedAt.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export default class CreateIndexStoppedAt1594902918301 implements MigrationInterface { +export class CreateIndexStoppedAt1594902918301 implements MigrationInterface { name = 'CreateIndexStoppedAt1594902918301'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts b/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts index 5723b7c738c39..391dbe2e8daab 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1610640521099-AddWebhookId.ts @@ -2,21 +2,21 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; -export default class AddWebhookId1610640521099 implements MigrationInterface { +export class AddWebhookId1610640521099 implements MigrationInterface { name = 'AddWebhookId1610640521099'; - public async up(queryRunner: QueryRunner): Promise { + async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` ADD `webhookId` varchar(255) NULL'); await queryRunner.query('CREATE UNIQUE INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity` (`webhookId`, `method`)'); } - public async down(queryRunner: QueryRunner): Promise { + async down(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query( - 'DROP INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity`', + 'DROP INDEX `IDX_' + tablePrefix + 'e1dddabccea3081178199d6004` ON `' + tablePrefix + 'webhook_entity`' ); await queryRunner.query('ALTER TABLE `' + tablePrefix + 'webhook_entity` DROP COLUMN `webhookId`'); } diff --git a/packages/cli/src/databases/mysqldb/migrations/index.ts b/packages/cli/src/databases/mysqldb/migrations/index.ts index baf42085de52f..ad7046e68f972 100644 --- a/packages/cli/src/databases/mysqldb/migrations/index.ts +++ b/packages/cli/src/databases/mysqldb/migrations/index.ts @@ -1,11 +1,11 @@ -import InitialMigration1588157391238 from './1588157391238-InitialMigration'; -import WebhookModel1592447867632 from './1592447867632-WebhookModel'; -import CreateIndexStoppedAt1594902918301 from './1594902918301-CreateIndexStoppedAt'; -import AddWebhookId1610640521099 from './1610640521099-AddWebhookId' +import { InitialMigration1588157391238 } from './1588157391238-InitialMigration'; +import { WebhookModel1592447867632 } from './1592447867632-WebhookModel'; +import { CreateIndexStoppedAt1594902918301 } from './1594902918301-CreateIndexStoppedAt'; +import { AddWebhookId1610640521099 } from './1610640521099-AddWebhookId'; -export default [ +export const mysqlMigrations = [ InitialMigration1588157391238, WebhookModel1592447867632, CreateIndexStoppedAt1594902918301, AddWebhookId1610640521099, -] +]; diff --git a/packages/cli/src/databases/postgresdb/WebhookEntity.ts b/packages/cli/src/databases/postgresdb/WebhookEntity.ts index db08a493075b4..a1329cebabb66 100644 --- a/packages/cli/src/databases/postgresdb/WebhookEntity.ts +++ b/packages/cli/src/databases/postgresdb/WebhookEntity.ts @@ -1,8 +1,8 @@ import { Column, Entity, - PrimaryColumn, Index, + PrimaryColumn, } from 'typeorm'; import { diff --git a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts index 911f236d23bb6..eace7a92fb732 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1587669153312-InitialMigration.ts @@ -3,7 +3,7 @@ import { import * as config from '../../../../config'; -export default class InitialMigration1587669153312 implements MigrationInterface { +export class InitialMigration1587669153312 implements MigrationInterface { name = 'InitialMigration1587669153312'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts b/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts index e4ae54ae0969e..0c195f9d5442f 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1589476000887-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export default class WebhookModel1589476000887 implements MigrationInterface { +export class WebhookModel1589476000887 implements MigrationInterface { name = 'WebhookModel1589476000887'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts b/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts index c0c99d313a4f3..664834082e10e 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1594828256133-CreateIndexStoppedAt.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export default class CreateIndexStoppedAt1594828256133 implements MigrationInterface { +export class CreateIndexStoppedAt1594828256133 implements MigrationInterface { name = 'CreateIndexStoppedAt1594828256133'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts b/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts index 2700096b88055..e57ada5064e1c 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1610632462428-AddWebhookId.ts @@ -2,10 +2,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; -export default class AddWebhookId1610632462428 implements MigrationInterface { +export class AddWebhookId1610632462428 implements MigrationInterface { name = 'AddWebhookId1610632462428'; - public async up(queryRunner: QueryRunner): Promise { + async up(queryRunner: QueryRunner): Promise { let tablePrefix = config.get('database.tablePrefix'); const tablePrefixPure = tablePrefix; const schema = config.get('database.postgresdb.schema'); @@ -15,11 +15,11 @@ export default class AddWebhookId1610632462428 implements MigrationInterface { await queryRunner.query(`ALTER TABLE ${tablePrefix}webhook_entity ADD "webhookId" character varying`); await queryRunner.query( - `CREATE UNIQUE INDEX "IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814" ON ${tablePrefix}webhook_entity ("webhookId", "method") `, + `CREATE UNIQUE INDEX "IDX_${tablePrefixPure}5c698bcd4092bc271cabdf7814" ON ${tablePrefix}webhook_entity ("webhookId", "method") ` ); } - public async down(queryRunner: QueryRunner): Promise { + async down(queryRunner: QueryRunner): Promise { let tablePrefix = config.get('database.tablePrefix'); const tablePrefixPure = tablePrefix; const schema = config.get('database.postgresdb.schema'); diff --git a/packages/cli/src/databases/postgresdb/migrations/index.ts b/packages/cli/src/databases/postgresdb/migrations/index.ts index 5ac9425e53b8a..d494b09ba5f1a 100644 --- a/packages/cli/src/databases/postgresdb/migrations/index.ts +++ b/packages/cli/src/databases/postgresdb/migrations/index.ts @@ -1,11 +1,11 @@ -import InitialMigration1587669153312 from './1587669153312-InitialMigration'; -import WebhookModel1589476000887 from './1589476000887-WebhookModel'; -import CreateIndexStoppedAt1594828256133 from './1594828256133-CreateIndexStoppedAt'; -import AddWebhookId1610632462428 from './1610632462428-AddWebhookId' +import { InitialMigration1587669153312 } from './1587669153312-InitialMigration'; +import { WebhookModel1589476000887 } from './1589476000887-WebhookModel'; +import { CreateIndexStoppedAt1594828256133 } from './1594828256133-CreateIndexStoppedAt'; +import { AddWebhookId1610632462428 } from './1610632462428-AddWebhookId'; -export default [ +export const postgresMigrations = [ InitialMigration1587669153312, WebhookModel1589476000887, CreateIndexStoppedAt1594828256133, AddWebhookId1610632462428, -] +]; diff --git a/packages/cli/src/databases/sqlite/WebhookEntity.ts b/packages/cli/src/databases/sqlite/WebhookEntity.ts index 04e2360981286..87beb0de03746 100644 --- a/packages/cli/src/databases/sqlite/WebhookEntity.ts +++ b/packages/cli/src/databases/sqlite/WebhookEntity.ts @@ -1,8 +1,8 @@ import { Column, Entity, - PrimaryColumn, Index, + PrimaryColumn, } from 'typeorm'; import { diff --git a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts index fe40dd66f03cf..09a0da911ae90 100644 --- a/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts +++ b/packages/cli/src/databases/sqlite/migrations/1588102412422-InitialMigration.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export default class InitialMigration1588102412422 implements MigrationInterface { +export class InitialMigration1588102412422 implements MigrationInterface { name = 'InitialMigration1588102412422'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts b/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts index 55db01991a3de..b011061e28405 100644 --- a/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts +++ b/packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts @@ -5,7 +5,7 @@ import { import * as config from '../../../../config'; -export default class WebhookModel1592445003908 implements MigrationInterface { +export class WebhookModel1592445003908 implements MigrationInterface { name = 'WebhookModel1592445003908'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts b/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts index 74322e416afdf..7c8104f06a388 100644 --- a/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts +++ b/packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts @@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; -export default class CreateIndexStoppedAt1594825041918 implements MigrationInterface { +export class CreateIndexStoppedAt1594825041918 implements MigrationInterface { name = 'CreateIndexStoppedAt1594825041918'; async up(queryRunner: QueryRunner): Promise { diff --git a/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts index 693cdeee4f8b7..f3282caea835d 100644 --- a/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts +++ b/packages/cli/src/databases/sqlite/migrations/1610570498276-AddWebhookId.ts @@ -2,35 +2,35 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; import * as config from '../../../../config'; -export default class AddWebhookId1610570498276 implements MigrationInterface { +export class AddWebhookId1610570498276 implements MigrationInterface { name = 'AddWebhookId1610570498276'; - public async up(queryRunner: QueryRunner): Promise { + async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query( - `CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))`, + `CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, PRIMARY KEY ("webhookPath", "method"))` ); await queryRunner.query( - `INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`, + `INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"` ); await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`); await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`); await queryRunner.query( - `CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") `, + `CREATE UNIQUE INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004" ON "${tablePrefix}webhook_entity" ("webhookId", "method") ` ); } - public async down(queryRunner: QueryRunner): Promise { + async down(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}e1dddabccea3081178199d6004"`); await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`); await queryRunner.query( - `CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`, + `CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))` ); await queryRunner.query( - `INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`, + `INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"` ); await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`); } diff --git a/packages/cli/src/databases/sqlite/migrations/index.ts b/packages/cli/src/databases/sqlite/migrations/index.ts index e15a8d632f398..5d86d29cc22f5 100644 --- a/packages/cli/src/databases/sqlite/migrations/index.ts +++ b/packages/cli/src/databases/sqlite/migrations/index.ts @@ -1,11 +1,11 @@ -import InitialMigration1588102412422 from './1588102412422-InitialMigration'; -import WebhookModel1592445003908 from './1592445003908-WebhookModel'; -import CreateIndexStoppedAt1594825041918 from './1594825041918-CreateIndexStoppedAt'; -import AddWebhookId1610570498276 from './1610570498276-AddWebhookId'; +import { InitialMigration1588102412422 } from './1588102412422-InitialMigration'; +import { WebhookModel1592445003908 } from './1592445003908-WebhookModel'; +import { CreateIndexStoppedAt1594825041918 } from './1594825041918-CreateIndexStoppedAt'; +import { AddWebhookId1610570498276 } from './1610570498276-AddWebhookId'; -export default [ +export const sqliteMigrations = [ InitialMigration1588102412422, WebhookModel1592445003908, CreateIndexStoppedAt1594825041918, AddWebhookId1610570498276, -] +]; From bceb9c3899346ab0d99d1b954cb33118ea0785bf Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 16:15:50 +0100 Subject: [PATCH 10/16] :wrench: dynamic path for webhook-test complete --- packages/cli/src/ActiveWorkflowRunner.ts | 24 ++++++++++----------- packages/cli/src/TestWebhooks.ts | 27 +++++++++++++++++++----- packages/core/src/ActiveWebhooks.ts | 15 ++++++++----- packages/workflow/src/Interfaces.ts | 1 + packages/workflow/src/NodeHelpers.ts | 6 ++++++ 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index be5b41f8085a4..a6c3a321dcfe8 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -120,26 +120,26 @@ export class ActiveWorkflowRunner { let webhook = await Db.collections.Webhook?.findOne({ webhookPath: path, method: httpMethod }) as IWebhookDb; let webhookId: string | undefined; + // check if path is dynamic if (webhook === undefined) { // check if a dynamic webhook path exists const pathElements = path.split('/'); webhookId = pathElements.shift(); webhook = await Db.collections.Webhook?.findOne({ webhookId, method: httpMethod }) as IWebhookDb; - if (webhook) { - path = webhook.webhookPath; - // extracting params from path - const webhookPathParams: IDataObject = {}; - webhook.webhookPath.split('/').forEach((ele, index) => { - if (ele.startsWith(':')) { - webhookPathParams[ele.slice(1)] = pathElements[index]; - } - }); - // write params to req.params - Object.assign(req.params, webhookPathParams); - } else { + if (webhook === undefined) { // The requested webhook is not registered throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); } + path = webhook.webhookPath; + // extracting params from path + const webhookPathParams: IDataObject = {}; + webhook.webhookPath.split('/').forEach((ele, index) => { + if (ele.startsWith(':')) { + webhookPathParams[ele.slice(1)] = pathElements[index]; + } + }); + // write params to req.params + Object.assign(req.params, webhookPathParams); } const workflowData = await Db.collections.Workflow!.findOne(webhook.workflowId); diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 5d81b8dd1e271..11796dd1a697e 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -18,6 +18,7 @@ import { WebhookHttpMethod, Workflow, WorkflowExecuteMode, + IDataObject, } from 'n8n-workflow'; @@ -54,14 +55,30 @@ export class TestWebhooks { * @memberof TestWebhooks */ async callTestWebhook(httpMethod: WebhookHttpMethod, path: string, request: express.Request, response: express.Response): Promise { - const webhookData: IWebhookData | undefined = this.activeWebhooks!.get(httpMethod, path); + let webhookData: IWebhookData | undefined = this.activeWebhooks!.get(httpMethod, path); + // check if path is dynamic if (webhookData === undefined) { - // The requested webhook is not registered - throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); + const pathElements = path.split('/'); + const webhookId = pathElements.shift(); + webhookData = this.activeWebhooks!.get(httpMethod, path, webhookId); + if (webhookData === undefined) { + // The requested webhook is not registered + throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404); + } + path = webhookData.path; + // extracting params from path + const webhookPathParams: IDataObject = {}; + path.split('/').forEach((ele, index) => { + if (ele.startsWith(':')) { + webhookPathParams[ele.slice(1)] = pathElements[index]; + } + }); + // write params to req.params + Object.assign(request.params, webhookPathParams); } - const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); + const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId); // TODO: Clean that duplication up one day and improve code generally if (this.testWebhookData[webhookKey] === undefined) { @@ -158,7 +175,7 @@ export class TestWebhooks { let key: string; const activatedKey: string[] = []; for (const webhookData of webhooks) { - key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); + key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId); activatedKey.push(key); diff --git a/packages/core/src/ActiveWebhooks.ts b/packages/core/src/ActiveWebhooks.ts index f4b1f1f86a0bf..fc1b98ab47ca0 100644 --- a/packages/core/src/ActiveWebhooks.ts +++ b/packages/core/src/ActiveWebhooks.ts @@ -35,7 +35,7 @@ export class ActiveWebhooks { throw new Error('Webhooks can only be added for saved workflows as an id is needed!'); } - const webhookKey = this.getWebhookKey(webhookData.httpMethod, webhookData.path); + const webhookKey = this.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId); //check that there is not a webhook already registed with that path/method if (this.webhookUrls[webhookKey] !== undefined) { @@ -72,11 +72,12 @@ export class ActiveWebhooks { * * @param {WebhookHttpMethod} httpMethod * @param {string} path + * @param {(string | undefined)} webhookId * @returns {(IWebhookData | undefined)} * @memberof ActiveWebhooks */ - get(httpMethod: WebhookHttpMethod, path: string): IWebhookData | undefined { - const webhookKey = this.getWebhookKey(httpMethod, path); + get(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): IWebhookData | undefined { + const webhookKey = this.getWebhookKey(httpMethod, path, webhookId); if (this.webhookUrls[webhookKey] === undefined) { return undefined; } @@ -116,10 +117,14 @@ export class ActiveWebhooks { * * @param {WebhookHttpMethod} httpMethod * @param {string} path + * @param {(string | undefined)} webhookId * @returns {string} * @memberof ActiveWebhooks */ - getWebhookKey(httpMethod: WebhookHttpMethod, path: string): string { + getWebhookKey(httpMethod: WebhookHttpMethod, path: string, webhookId?: string): string { + if (webhookId) { + return `${httpMethod}|${webhookId}`; + } return `${httpMethod}|${path}`; } @@ -147,7 +152,7 @@ export class ActiveWebhooks { for (const webhookData of webhooks) { await workflow.runWebhookMethod('delete', webhookData, NodeExecuteFunctions, mode, this.testWebhooks); - delete this.webhookUrls[this.getWebhookKey(webhookData.httpMethod, webhookData.path)]; + delete this.webhookUrls[this.getWebhookKey(webhookData.httpMethod, webhookData.path, webhookData.webhookId)]; } // Remove also the workflow-webhook entry diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 6630a559cd7f3..b0309203091e2 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -567,6 +567,7 @@ export interface IWebhookData { webhookDescription: IWebhookDescription; workflowId: string; workflowExecuteAdditionalData: IWorkflowExecuteAdditionalData; + webhookId?: string; } export interface IWebhookDescription { diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 3082b5d3dd464..91680346d6448 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -779,6 +779,11 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: continue; } + let webhookId: string | undefined; + if ((path.startsWith(':') || path.includes('/:')) && node.webhookId) { + webhookId = node.webhookId + } + returnData.push({ httpMethod: httpMethod.toString() as WebhookHttpMethod, node: node.name, @@ -786,6 +791,7 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: webhookDescription, workflowId, workflowExecuteAdditionalData: additionalData, + webhookId, }); } From 5a0ef34a2d44d6459af769c710dc865c17481b27 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 16:18:05 +0100 Subject: [PATCH 11/16] :art: fix lint issues --- packages/cli/src/TestWebhooks.ts | 2 +- packages/workflow/src/NodeHelpers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 11796dd1a697e..2a196454c0650 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -13,12 +13,12 @@ import { } from 'n8n-core'; import { + IDataObject, IWebhookData, IWorkflowExecuteAdditionalData, WebhookHttpMethod, Workflow, WorkflowExecuteMode, - IDataObject, } from 'n8n-workflow'; diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 91680346d6448..d10651e83bb0c 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -781,7 +781,7 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData: let webhookId: string | undefined; if ((path.startsWith(':') || path.includes('/:')) && node.webhookId) { - webhookId = node.webhookId + webhookId = node.webhookId; } returnData.push({ From d7ccaa9c030ee74b28ce4d58343bf5f947bcc65b Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 16:35:49 +0100 Subject: [PATCH 12/16] :art: fix typescript issue --- packages/cli/src/TestWebhooks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 2a196454c0650..c9d112a29c59d 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -98,7 +98,7 @@ export class TestWebhooks { return new Promise(async (resolve, reject) => { try { const executionMode = 'manual'; - const executionId = await WebhookHelpers.executeWebhook(workflow, webhookData, this.testWebhookData[webhookKey].workflowData, workflowStartNode, executionMode, this.testWebhookData[webhookKey].sessionId, request, response, (error: Error | null, data: IResponseCallbackData) => { + const executionId = await WebhookHelpers.executeWebhook(workflow, webhookData!, this.testWebhookData[webhookKey].workflowData, workflowStartNode, executionMode, this.testWebhookData[webhookKey].sessionId, request, response, (error: Error | null, data: IResponseCallbackData) => { if (error !== null) { return reject(error); } @@ -115,7 +115,7 @@ export class TestWebhooks { // Inform editor-ui that webhook got received if (this.testWebhookData[webhookKey].sessionId !== undefined) { const pushInstance = Push.getInstance(); - pushInstance.send('testWebhookReceived', { workflowId: webhookData.workflowId, executionId }, this.testWebhookData[webhookKey].sessionId!); + pushInstance.send('testWebhookReceived', { workflowId: webhookData!.workflowId, executionId }, this.testWebhookData[webhookKey].sessionId!); } } catch (error) { From 7687de281428557793748fd5ea5bd9dc62a8f5df Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 16:50:27 +0100 Subject: [PATCH 13/16] :zap: add error message for dynamic webhook-test --- packages/core/src/ActiveWebhooks.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/ActiveWebhooks.ts b/packages/core/src/ActiveWebhooks.ts index fc1b98ab47ca0..bd8248dc8fbf7 100644 --- a/packages/core/src/ActiveWebhooks.ts +++ b/packages/core/src/ActiveWebhooks.ts @@ -39,6 +39,9 @@ export class ActiveWebhooks { //check that there is not a webhook already registed with that path/method if (this.webhookUrls[webhookKey] !== undefined) { + if (webhookData.webhookId) { + throw new Error(`Test-Webhook "${webhookData.node}" can not be activated! Please duplicate "${webhookData.node}" and delete the currently existing one.`); + } throw new Error(`Test-Webhook can not be activated because another one with the same method "${webhookData.httpMethod}" and path "${webhookData.path}" is already active!`); } From 5657a38ade1f6ff2201d301ef924c64f6e3d5055 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 17:38:26 +0100 Subject: [PATCH 14/16] :hammer: improve handling of leading `/` --- packages/cli/src/ActiveWorkflowRunner.ts | 3 +-- packages/workflow/src/NodeHelpers.ts | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index a6c3a321dcfe8..e88d66019fe25 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -275,7 +275,7 @@ export class ActiveWorkflowRunner { webhook.webhookId = node.webhookId; } - if (webhook.webhookPath.charAt(0) === '/') { + if (webhook.webhookPath.startsWith('/')) { webhook.webhookPath = webhook.webhookPath.slice(1); } @@ -302,7 +302,6 @@ export class ActiveWorkflowRunner { // TODO check if there is standard error code for duplicate key violation that works // with all databases if (error.name === 'MongoError' || error.name === 'QueryFailedError') { - console.log(error); errorMessage = error.parameters.length === 5 ? `Node [${webhook.node}] can't be saved, please duplicate [${webhook.node}] and delete the currently existing one.` : `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`; diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index d10651e83bb0c..afcfc334d7e7d 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -893,6 +893,9 @@ export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INo // setting this to false to prefix the webhookId isFullPath = false; } + if (path.startsWith('/')) { + path = path.slice(1); + } return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path, isFullPath)}`; } From 6f700adc5b1f288dd912cdead77f4e3027d27dfd Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 19:06:55 +0100 Subject: [PATCH 15/16] :fire: remove MongoDB as database option --- packages/cli/config/index.ts | 10 +--- packages/cli/migrations/ormconfig.ts | 21 +------- packages/cli/package.json | 1 - packages/cli/src/ActiveWorkflowRunner.ts | 7 +-- packages/cli/src/Db.ts | 15 ------ packages/cli/src/Interfaces.ts | 5 +- packages/cli/src/databases/index.ts | 2 - .../databases/mongodb/CredentialsEntity.ts | 41 --------------- .../src/databases/mongodb/ExecutionEntity.ts | 52 ------------------- .../src/databases/mongodb/WebhookEntity.ts | 35 ------------- .../src/databases/mongodb/WorkflowEntity.ts | 48 ----------------- packages/cli/src/databases/mongodb/index.ts | 5 -- .../151594910478695-CreateIndexStoppedAt.ts | 22 -------- .../1587563438936-InitialMigration.ts | 11 ---- .../migrations/1592679094242-WebhookModel.ts | 23 -------- .../src/databases/mongodb/migrations/index.ts | 9 ---- 16 files changed, 4 insertions(+), 303 deletions(-) delete mode 100644 packages/cli/src/databases/mongodb/CredentialsEntity.ts delete mode 100644 packages/cli/src/databases/mongodb/ExecutionEntity.ts delete mode 100644 packages/cli/src/databases/mongodb/WebhookEntity.ts delete mode 100644 packages/cli/src/databases/mongodb/WorkflowEntity.ts delete mode 100644 packages/cli/src/databases/mongodb/index.ts delete mode 100644 packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts delete mode 100644 packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts delete mode 100644 packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts delete mode 100644 packages/cli/src/databases/mongodb/migrations/index.ts diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 0793e8c7f131b..471774ce2f361 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -8,18 +8,10 @@ const config = convict({ database: { type: { doc: 'Type of database to use', - format: ['sqlite', 'mariadb', 'mongodb', 'mysqldb', 'postgresdb'], + format: ['sqlite', 'mariadb', 'mysqldb', 'postgresdb'], default: 'sqlite', env: 'DB_TYPE', }, - mongodb: { - connectionUrl: { - doc: 'MongoDB Connection URL', - format: '*', - default: 'mongodb://user:password@localhost:27017/database', - env: 'DB_MONGODB_CONNECTION_URL', - }, - }, tablePrefix: { doc: 'Prefix for table names', format: '*', diff --git a/packages/cli/migrations/ormconfig.ts b/packages/cli/migrations/ormconfig.ts index 1ea583beb410a..b6e8b40dc5081 100644 --- a/packages/cli/migrations/ormconfig.ts +++ b/packages/cli/migrations/ormconfig.ts @@ -1,4 +1,4 @@ -import {MongoDb, SQLite, MySQLDb, PostgresDb} from '../src/databases/index'; +import { SQLite, MySQLDb, PostgresDb} from '../src/databases/index'; module.exports = [ { @@ -19,25 +19,6 @@ module.exports = [ "subscribersDir": "./src/databases/sqlite/subscribers" } }, - { - "name": "mongodb", - "type": "mongodb", - "logging": false, - "entities": Object.values(MongoDb), - "url": "mongodb://root:example@localhost:27017/n8n", - "authSource": 'admin', - "migrations": [ - "./src/databases/mongodb/migrations/*.ts" - ], - "subscribers": [ - "src/subscriber/**/*.ts" - ], - "cli": { - "entitiesDir": "./src/databases/mongodb", - "migrationsDir": "./src/databases/mongodb/Migrations", - "subscribersDir": "./src/databases/mongodb/Subscribers" - } - }, { "name": "postgres", "type": "postgres", diff --git a/packages/cli/package.json b/packages/cli/package.json index aba3cf5d6f1aa..f14b7b73e281d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -101,7 +101,6 @@ "jwks-rsa": "~1.9.0", "localtunnel": "^2.0.0", "lodash.get": "^4.4.2", - "mongodb": "^3.5.5", "mysql2": "~2.1.0", "n8n-core": "~0.58.0", "n8n-editor-ui": "~0.71.0", diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index e88d66019fe25..f1517e5644ed4 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -301,7 +301,7 @@ export class ActiveWorkflowRunner { // if it's a workflow from the the insert // TODO check if there is standard error code for duplicate key violation that works // with all databases - if (error.name === 'MongoError' || error.name === 'QueryFailedError') { + if (error.name === 'QueryFailedError') { errorMessage = error.parameters.length === 5 ? `Node [${webhook.node}] can't be saved, please duplicate [${webhook.node}] and delete the currently existing one.` : `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`; @@ -350,11 +350,6 @@ export class ActiveWorkflowRunner { await WorkflowHelpers.saveStaticData(workflow); - // if it's a mongo objectId convert it to string - if (typeof workflowData.id === 'object') { - workflowData.id = workflowData.id.toString(); - } - const webhook = { workflowId: workflowData.id, } as IWebhookDb; diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index 67565043e9bc3..7e9bd7f861ba3 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -19,7 +19,6 @@ import { TlsOptions } from 'tls'; import * as config from '../config'; import { - MongoDb, MySQLDb, PostgresDb, SQLite, @@ -33,7 +32,6 @@ export let collections: IDatabaseCollections = { }; import { postgresMigrations } from './databases/postgresdb/migrations'; -import { mongodbMigrations } from './databases/mongodb/migrations'; import { mysqlMigrations } from './databases/mysqldb/migrations'; import { sqliteMigrations } from './databases/sqlite/migrations'; @@ -49,19 +47,6 @@ export async function init(): Promise { const entityPrefix = config.get('database.tablePrefix'); switch (dbType) { - case 'mongodb': - entities = MongoDb; - connectionOptions = { - type: 'mongodb', - entityPrefix, - url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string, - useNewUrlParser: true, - migrations: mongodbMigrations, - migrationsRun: true, - migrationsTableName: `${entityPrefix}migrations`, - }; - break; - case 'postgresdb': entities = PostgresDb; diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 4e63151c9cca7..707ca56170d48 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -104,7 +104,7 @@ export interface ICredentialsDecryptedResponse extends ICredentialsDecryptedDb { id: string; } -export type DatabaseType = 'mariadb' | 'mongodb' | 'postgresdb' | 'mysqldb' | 'sqlite'; +export type DatabaseType = 'mariadb' | 'postgresdb' | 'mysqldb' | 'sqlite'; export type SaveExecutionDataType = 'all' | 'none'; export interface IExecutionBase { @@ -248,9 +248,6 @@ export interface IN8nConfig { export interface IN8nConfigDatabase { type: DatabaseType; - mongodb: { - connectionUrl: string; - }; postgresdb: { host: string; password: string; diff --git a/packages/cli/src/databases/index.ts b/packages/cli/src/databases/index.ts index 48ba5c86eb575..4cf2fbb0fb9da 100644 --- a/packages/cli/src/databases/index.ts +++ b/packages/cli/src/databases/index.ts @@ -1,10 +1,8 @@ -import * as MongoDb from './mongodb'; import * as PostgresDb from './postgresdb'; import * as SQLite from './sqlite'; import * as MySQLDb from './mysqldb'; export { - MongoDb, PostgresDb, SQLite, MySQLDb, diff --git a/packages/cli/src/databases/mongodb/CredentialsEntity.ts b/packages/cli/src/databases/mongodb/CredentialsEntity.ts deleted file mode 100644 index f2fa830cc9e3f..0000000000000 --- a/packages/cli/src/databases/mongodb/CredentialsEntity.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - ICredentialNodeAccess, -} from 'n8n-workflow'; - -import { - ICredentialsDb, -} from '../../'; - -import { - Column, - Entity, - Index, - ObjectID, - ObjectIdColumn, -} from 'typeorm'; - -@Entity() -export class CredentialsEntity implements ICredentialsDb { - - @ObjectIdColumn() - id: ObjectID; - - @Column() - name: string; - - @Column() - data: string; - - @Index() - @Column() - type: string; - - @Column('json') - nodesAccess: ICredentialNodeAccess[]; - - @Column('Date') - createdAt: Date; - - @Column('Date') - updatedAt: Date; -} diff --git a/packages/cli/src/databases/mongodb/ExecutionEntity.ts b/packages/cli/src/databases/mongodb/ExecutionEntity.ts deleted file mode 100644 index 02a639d66a38e..0000000000000 --- a/packages/cli/src/databases/mongodb/ExecutionEntity.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - WorkflowExecuteMode, -} from 'n8n-workflow'; - -import { - IExecutionFlattedDb, - IWorkflowDb, -} from '../../'; - -import { - Column, - Entity, - Index, - ObjectID, - ObjectIdColumn, - } from 'typeorm'; - -@Entity() -export class ExecutionEntity implements IExecutionFlattedDb { - - @ObjectIdColumn() - id: ObjectID; - - @Column() - data: string; - - @Column() - finished: boolean; - - @Column() - mode: WorkflowExecuteMode; - - @Column() - retryOf: string; - - @Column() - retrySuccessId: string; - - @Column('Date') - startedAt: Date; - - @Index() - @Column('Date') - stoppedAt: Date; - - @Column('json') - workflowData: IWorkflowDb; - - @Index() - @Column() - workflowId: string; -} diff --git a/packages/cli/src/databases/mongodb/WebhookEntity.ts b/packages/cli/src/databases/mongodb/WebhookEntity.ts deleted file mode 100644 index 9f70f309d5dbf..0000000000000 --- a/packages/cli/src/databases/mongodb/WebhookEntity.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - Column, - Entity, - Index, - ObjectID, - ObjectIdColumn, -} from 'typeorm'; - -import { - IWebhookDb, - } from '../../Interfaces'; - -@Entity() -@Index(["webhookPath", "method"], { unique: true }) -@Index(["webhookId", "method"], { unique: true }) -export class WebhookEntity implements IWebhookDb { - - @ObjectIdColumn() - id: ObjectID; - - @Column() - workflowId: number; - - @Column() - webhookPath: string; - - @Column() - method: string; - - @Column() - node: string; - - @Column() - webhookId: string; -} diff --git a/packages/cli/src/databases/mongodb/WorkflowEntity.ts b/packages/cli/src/databases/mongodb/WorkflowEntity.ts deleted file mode 100644 index 19253485f2721..0000000000000 --- a/packages/cli/src/databases/mongodb/WorkflowEntity.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - IConnections, - IDataObject, - INode, - IWorkflowSettings, -} from 'n8n-workflow'; - -import { - IWorkflowDb, -} from '../../'; - -import { - Column, - Entity, - ObjectID, - ObjectIdColumn, -} from 'typeorm'; - -@Entity() -export class WorkflowEntity implements IWorkflowDb { - - @ObjectIdColumn() - id: ObjectID; - - @Column() - name: string; - - @Column() - active: boolean; - - @Column('json') - nodes: INode[]; - - @Column('json') - connections: IConnections; - - @Column('Date') - createdAt: Date; - - @Column('Date') - updatedAt: Date; - - @Column('json') - settings?: IWorkflowSettings; - - @Column('json') - staticData?: IDataObject; -} diff --git a/packages/cli/src/databases/mongodb/index.ts b/packages/cli/src/databases/mongodb/index.ts deleted file mode 100644 index bd6b9abd60093..0000000000000 --- a/packages/cli/src/databases/mongodb/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './CredentialsEntity'; -export * from './ExecutionEntity'; -export * from './WorkflowEntity'; -export * from './WebhookEntity'; - diff --git a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts b/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts deleted file mode 100644 index e9cc890e8b586..0000000000000 --- a/packages/cli/src/databases/mongodb/migrations/151594910478695-CreateIndexStoppedAt.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { MigrationInterface } from "typeorm"; -import { - MongoQueryRunner, -} from 'typeorm/driver/mongodb/MongoQueryRunner'; - -import * as config from '../../../../config'; - -export class CreateIndexStoppedAt1594910478695 implements MigrationInterface { - name = 'CreateIndexStoppedAt1594910478695'; - - async up(queryRunner: MongoQueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.manager.createCollectionIndex(`${tablePrefix}execution_entity`, 'stoppedAt', { name: `IDX_${tablePrefix}execution_entity_stoppedAt` }); - } - - async down(queryRunner: MongoQueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.manager.dropCollectionIndex - (`${tablePrefix}execution_entity`, `IDX_${tablePrefix}execution_entity_stoppedAt`); - } - -} diff --git a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts b/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts deleted file mode 100644 index df2785c3500ea..0000000000000 --- a/packages/cli/src/databases/mongodb/migrations/1587563438936-InitialMigration.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class InitialMigration1587563438936 implements MigrationInterface { - - async up(queryRunner: QueryRunner): Promise { - } - - async down(queryRunner: QueryRunner): Promise { - } - -} diff --git a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts b/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts deleted file mode 100644 index 22c4db53fa1b3..0000000000000 --- a/packages/cli/src/databases/mongodb/migrations/1592679094242-WebhookModel.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { - MigrationInterface, -} from 'typeorm'; - -import * as config from '../../../../config'; - -import { - MongoQueryRunner, -} from 'typeorm/driver/mongodb/MongoQueryRunner'; - -export class WebhookModel1592679094242 implements MigrationInterface { - name = 'WebhookModel1592679094242'; - - async up(queryRunner: MongoQueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.manager.createCollectionIndex(`${tablePrefix}webhook_entity`, ['webhookPath', 'method'], { unique: true, background: false }); - } - - async down(queryRunner: MongoQueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.dropTable(`${tablePrefix}webhook_entity`); - } -} diff --git a/packages/cli/src/databases/mongodb/migrations/index.ts b/packages/cli/src/databases/mongodb/migrations/index.ts deleted file mode 100644 index 4b4239eb3db6b..0000000000000 --- a/packages/cli/src/databases/mongodb/migrations/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { InitialMigration1587563438936 } from './1587563438936-InitialMigration'; -import { WebhookModel1592679094242 } from './1592679094242-WebhookModel'; -import { CreateIndexStoppedAt1594910478695 } from './151594910478695-CreateIndexStoppedAt'; - -export const mongodbMigrations = [ - InitialMigration1587563438936, - WebhookModel1592679094242, - CreateIndexStoppedAt1594910478695, -]; From 1663a1c84cad6721a3af660fcfbac0d3ec1be45e Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck Date: Fri, 15 Jan 2021 19:08:11 +0100 Subject: [PATCH 16/16] :pencil: fix READMEs --- docker/compose/subfolderWithSSL/README.md | 4 ---- docker/images/n8n/README.md | 29 +---------------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/docker/compose/subfolderWithSSL/README.md b/docker/compose/subfolderWithSSL/README.md index 61fcb5b7e74ef..43cf5a1484d07 100644 --- a/docker/compose/subfolderWithSSL/README.md +++ b/docker/compose/subfolderWithSSL/README.md @@ -20,7 +20,3 @@ To stop it execute: ``` docker-compose stop ``` - -## Configuration - -The default name of the database, user and password for MongoDB can be changed in the `.env` file in the current directory. diff --git a/docker/images/n8n/README.md b/docker/images/n8n/README.md index b10d899325021..ef0d7123e7c7b 100644 --- a/docker/images/n8n/README.md +++ b/docker/images/n8n/README.md @@ -107,7 +107,7 @@ docker run -it --rm \ ### Start with other Database By default n8n uses SQLite to save credentials, past executions and workflows. -n8n however also supports MongoDB, PostgresDB and MySQL. To use them simply a few +n8n however also supports PostgresDB, MySQL and MariaDB. To use them simply a few environment variables have to be set. It is important to still persist the data in the `/root/.n8n` folder. The reason @@ -117,32 +117,6 @@ for the credentials. If none gets found n8n creates automatically one on startup. In case credentials are already saved with a different encryption key it can not be used anymore as encrypting it is not possible anymore. -#### Use with MongoDB - -> **WARNING**: Use Postgres if possible! Mongo has problems with saving large -> amounts of data in a document and causes also other problems. So support will -> may be dropped in the future. - -Replace the following placeholders with the actual data: - - MONGO_DATABASE - - MONGO_HOST - - MONGO_PORT - - MONGO_USER - - MONGO_PASSWORD - -``` -docker run -it --rm \ - --name n8n \ - -p 5678:5678 \ - -e DB_TYPE=mongodb \ - -e DB_MONGODB_CONNECTION_URL="mongodb://:@:/" \ - -v ~/.n8n:/home/node/.n8n \ - n8nio/n8n \ - n8n start -``` - -A full working setup with docker-compose can be found [here](https://github.com/n8n-io/n8n/blob/master/docker/compose/withMongo/README.md) - #### Use with PostgresDB Replace the following placeholders with the actual data: @@ -203,7 +177,6 @@ with the given name. That makes it possible to load data easily from Docker- and Kubernetes-Secrets. The following environment variables support file input: - - DB_MONGODB_CONNECTION_URL_FILE - DB_POSTGRESDB_DATABASE_FILE - DB_POSTGRESDB_HOST_FILE - DB_POSTGRESDB_PASSWORD_FILE