Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions src/database/migration/1788076191928-add-email-template-indexes.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/email-marketing/entities/email-template.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UpdateDateColumn,
DeleteDateColumn,
VersionColumn,
Index,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

Expand All @@ -22,6 +23,7 @@ export class EmailTemplate {
version: number;

@ApiProperty()
@Index('IDX_email_templates_name')
@Column()
name: string;

Expand All @@ -38,6 +40,7 @@ export class EmailTemplate {
textContent?: string;

@ApiProperty({ required: false })
@Index('IDX_email_templates_category')
@Column({ nullable: true })
category?: string;

Expand All @@ -50,10 +53,12 @@ export class EmailTemplate {
thumbnailUrl?: string;

@ApiProperty()
@Index('IDX_email_templates_is_active')
@Column({ default: true })
isActive: boolean;

@ApiProperty()
@Index('IDX_email_templates_created_at')
@CreateDateColumn()
createdAt: Date;

Expand Down
37 changes: 37 additions & 0 deletions src/migrations/1805000000000-add-email-template-indexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

/**
* Add the supporting indexes used by the email-template lookup and list paths.
*
* Common access patterns for this table include:
* - filtering by template `name`
* - filtering by `category`
* - filtering active/inactive templates via `isActive`
* - ordering recent templates by `createdAt`
*
* These indexes align the database schema with the entity metadata and avoid
* needing to rely on `synchronize` for existing databases.
*/
export class AddEmailTemplateIndexes1805000000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_email_templates_name" ON "email_templates" ("name")',
);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_email_templates_category" ON "email_templates" ("category")',
);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_email_templates_is_active" ON "email_templates" ("isActive")',
);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_email_templates_created_at" ON "email_templates" ("createdAt")',
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('DROP INDEX IF EXISTS "IDX_email_templates_created_at"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_email_templates_is_active"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_email_templates_category"');
await queryRunner.query('DROP INDEX IF EXISTS "IDX_email_templates_name"');
}
}
Loading