import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_items" ADD "item_id" uuid`,
    );
    await queryRunner.query(
      `ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transactions" ADD "customer_category_id" uuid`,
    );

    await queryRunner.query(
      `ALTER TABLE "transaction_items" ADD CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    );
    await queryRunner.query(
      `ALTER TABLE "transactions" ADD CONSTRAINT "FK_08dc8138714894a66e94820766d" FOREIGN KEY ("customer_category_id") REFERENCES "vip_categories"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "transactions" DROP CONSTRAINT "FK_08dc8138714894a66e94820766d"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_items" DROP CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transactions" ADD "customer_category_id" character varying`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_items" ADD "item_id" character varying`,
    );
  }
}
