import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateEmailTemplates1782115000000 implements MigrationInterface {
  name = 'CreateEmailTemplates1782115000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS \`email_templates\` (
        \`id\` varchar(36) NOT NULL,
        \`template_name\` varchar(255) NOT NULL,
        \`subject\` varchar(255) NOT NULL,
        \`body_html\` text NOT NULL,
        \`variables\` json NULL,
        \`description\` varchar(255) NULL,
        \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
        \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
        UNIQUE INDEX \`IDX_email_templates_template_name\` (\`template_name\`),
        PRIMARY KEY (\`id\`)
      ) ENGINE=InnoDB
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE IF EXISTS \`email_templates\``);
  }
}
