import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddItemProfit1723706764654 implements MigrationInterface {
  name = 'AddOtherType1723706764655';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "items" ADD "breakdown_bundling" boolean NOT NULL DEFAULT false`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."item_categories_item_type_enum" RENAME TO "item_categories_item_type_enum_old"`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."item_categories_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum" USING "item_type"::"text"::"public"."item_categories_item_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."item_categories_item_type_enum_old"`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."items_item_type_enum" RENAME TO "items_item_type_enum_old"`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."items_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum" USING "item_type"::"text"::"public"."items_item_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
    );
    await queryRunner.query(`DROP TYPE "public"."items_item_type_enum_old"`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TYPE "public"."items_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum_old" USING "item_type"::"text"::"public"."items_item_type_enum_old"`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
    );
    await queryRunner.query(`DROP TYPE "public"."items_item_type_enum"`);
    await queryRunner.query(
      `ALTER TYPE "public"."items_item_type_enum_old" RENAME TO "items_item_type_enum"`,
    );
    await queryRunner.query(
      `CREATE TYPE "public"."item_categories_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum_old" USING "item_type"::"text"::"public"."item_categories_item_type_enum_old"`,
    );
    await queryRunner.query(
      `ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
    );
    await queryRunner.query(
      `DROP TYPE "public"."item_categories_item_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TYPE "public"."item_categories_item_type_enum_old" RENAME TO "item_categories_item_type_enum"`,
    );
    await queryRunner.query(
      `ALTER TABLE "items" DROP COLUMN "breakdown_bundling"`,
    );
  }
}
