diff --git a/packages/cli/src/databases/sqlite/WebhookEntity.ts b/packages/cli/src/databases/sqlite/WebhookEntity.ts index a78fd34ae9..04e2360981 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 09a0da911a..fe40dd66f0 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 b011061e28..55db01991a 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 596ff81d19..74322e416a 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 0000000000..6879eaf9b1 --- /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 d6a8ffad1c..e15a8d632f 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, +]