import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TYPE "public"."transaction_demographies_nationality_enum" RENAME TO "transaction_demographies_nationality_enum_old"`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign', 'mix', 'foreigner')`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" TYPE "public"."transaction_demographies_nationality_enum" USING "nationality"::"text"::"public"."transaction_demographies_nationality_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" SET DEFAULT 'local'`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."transaction_demographies_nationality_enum_old"`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TYPE "public"."transaction_demographies_nationality_enum_old" AS ENUM('local', 'foreign', 'mix')`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" TYPE "public"."transaction_demographies_nationality_enum_old" USING "nationality"::"text"::"public"."transaction_demographies_nationality_enum_old"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" SET DEFAULT 'local'`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."transaction_demographies_nationality_enum"`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."transaction_demographies_nationality_enum_old" RENAME TO "transaction_demographies_nationality_enum"`,
    );
  }
}
