import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`CREATE TABLE IF NOT EXISTS "custom_emojis" (
      "id" TEXT PRIMARY KEY NOT NULL,
      "name" TEXT NOT NULL,
      "creatorUserId" TEXT NOT NULL,
      "dataUrl" TEXT NOT NULL,
      "hash" TEXT NOT NULL,
      "mime" TEXT NOT NULL,
      "size" INTEGER NOT NULL,
      "createdAt" INTEGER NOT NULL,
      "updatedAt" INTEGER NOT NULL
    )`);
    await queryRunner.query(`CREATE INDEX IF NOT EXISTS "idx_custom_emojis_updated_at" ON "custom_emojis" ("updatedAt")`);
    await queryRunner.query(`CREATE INDEX IF NOT EXISTS "idx_custom_emojis_creator" ON "custom_emojis" ("creatorUserId")`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP INDEX IF EXISTS "idx_custom_emojis_creator"`);
    await queryRunner.query(`DROP INDEX IF EXISTS "idx_custom_emojis_updated_at"`);
    await queryRunner.query(`DROP TABLE IF EXISTS "custom_emojis"`);
  }
}