import { MigrationInterface, QueryRunner, TableColumn, TableIndex } from "typeorm";

export class AddPageViewCountry1748700000000 implements MigrationInterface {
  name = "AddPageViewCountry1748700000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.addColumn("page_views", new TableColumn({ name: "country", type: "varchar", length: "100", isNullable: true }));
    await queryRunner.addColumn("page_views", new TableColumn({ name: "country_code", type: "varchar", length: "2", isNullable: true }));
    await queryRunner.createIndex("page_views", new TableIndex({ name: "IDX_page_views_country", columnNames: ["country"] }));
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropIndex("page_views", "IDX_page_views_country");
    await queryRunner.dropColumn("page_views", "country_code");
    await queryRunner.dropColumn("page_views", "country");
  }
}
