diff --git a/src/email-marketing/entities/automation-action.entity.ts b/src/email-marketing/entities/automation-action.entity.ts index e50a2841..11ef3a97 100644 --- a/src/email-marketing/entities/automation-action.entity.ts +++ b/src/email-marketing/entities/automation-action.entity.ts @@ -6,6 +6,7 @@ import { JoinColumn, DeleteDateColumn, VersionColumn, + Index, } from 'typeorm'; import { ApiProperty } from '@nestjs/swagger'; import { AutomationWorkflow } from './automation-workflow.entity'; @@ -15,6 +16,8 @@ import { ActionType } from '../enums/action-type.enum'; * Represents the automation Action entity. */ @Entity('automation_actions') +@Index('IDX_automation_actions_workflowId_order', ['workflowId', 'order']) +@Index('IDX_automation_actions_workflowId_type', ['workflowId', 'type']) export class AutomationAction { @ApiProperty() @PrimaryGeneratedColumn('uuid') @@ -24,6 +27,7 @@ export class AutomationAction { version: number; @ApiProperty() + @Index('IDX_automation_actions_workflowId') @Column() workflowId: string; @@ -32,6 +36,7 @@ export class AutomationAction { workflow: AutomationWorkflow; @ApiProperty({ enum: ActionType }) + @Index('IDX_automation_actions_type') @Column({ type: 'enum', enum: ActionType }) type: ActionType; @@ -40,6 +45,7 @@ export class AutomationAction { config: Record; @ApiProperty() + @Index('IDX_automation_actions_order') @Column({ default: 0 }) order: number; @@ -47,6 +53,7 @@ export class AutomationAction { @Column({ type: 'text', nullable: true }) description?: string; + @Index('IDX_automation_actions_deletedAt') @DeleteDateColumn() deletedAt?: Date; } diff --git a/src/migrations/1800000000001-add-automation-action-indexes.ts b/src/migrations/1800000000001-add-automation-action-indexes.ts new file mode 100644 index 00000000..123fcf1d --- /dev/null +++ b/src/migrations/1800000000001-add-automation-action-indexes.ts @@ -0,0 +1,33 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddAutomationActionIndexes1800000000001 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_workflowId" ON "automation_actions" ("workflowId")', + ); + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_type" ON "automation_actions" ("type")', + ); + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_order" ON "automation_actions" ("order")', + ); + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_deletedAt" ON "automation_actions" ("deletedAt")', + ); + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_workflowId_order" ON "automation_actions" ("workflowId", "order")', + ); + await queryRunner.query( + 'CREATE INDEX IF NOT EXISTS "IDX_automation_actions_workflowId_type" ON "automation_actions" ("workflowId", "type")', + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_workflowId_type"'); + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_workflowId_order"'); + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_deletedAt"'); + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_order"'); + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_type"'); + await queryRunner.query('DROP INDEX IF EXISTS "IDX_automation_actions_workflowId"'); + } +}