import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE \`discounts\` 
ADD COLUMN \`promotionPlanId\` INT(11) NULL DEFAULT NULL AFTER \`customerId\`,
ADD INDEX \`fk_discounts_promotion_plans1_idx\` (\`promotionPlanId\` ASC)`);

    await queryRunner.query(`ALTER TABLE \`promotion_plans\` 
ADD COLUMN \`deleted\` TINYINT(1) NOT NULL DEFAULT 0 AFTER \`section\`;`);

    await queryRunner.query(`ALTER TABLE \`discounts\` 
ADD CONSTRAINT \`fk_discounts_promotion_plans1\`
  FOREIGN KEY (\`promotionPlanId\`)
  REFERENCES \`promotion_plans\` (\`id\`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;
  `);

    await queryRunner.query(
      `ALTER TABLE \`promotion_plans\` CHANGE \`startDate\` \`startDate\` DATE NULL DEFAULT NULL, CHANGE \`endDate\` \`endDate\` DATE NULL DEFAULT NULL;`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    //
  }
}
