import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "transaction_item_breakdowns" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "item_id" character varying NOT NULL, "item_name" character varying NOT NULL, "hpp" bigint, "base_price" bigint, "item_rates" bigint, "transaction_item_id" uuid, CONSTRAINT "PK_e04a30c648d3ba8778e9fb67fdd" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      `ALTER TABLE "transaction_item_breakdowns" ADD CONSTRAINT "FK_b8c63b1f3ecace500587da713ae" FOREIGN KEY ("transaction_item_id") REFERENCES "transaction_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "transaction_item_breakdowns" DROP CONSTRAINT "FK_b8c63b1f3ecace500587da713ae"`,
    );
    await queryRunner.query(`DROP TABLE "transaction_item_breakdowns"`);
  }
}
