🚧 add webhookId to webhook entity, 🔧 refactor migrations

This commit is contained in:
Ben Hesseldieck 2021-01-13 20:54:59 +01:00
parent 501c5a5e90
commit d91b0f52cb
6 changed files with 48 additions and 7 deletions

View file

@ -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;
}

View file

@ -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<void> {

View file

@ -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<void> {

View file

@ -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<void> {
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<void> {

View file

@ -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<void> {
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<void> {
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"`);
}
}

View file

@ -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,
]