import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "vip_codes" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "code" character varying NOT NULL, "discount" integer NOT NULL, "vip_category_id" uuid NOT NULL, CONSTRAINT "PK_423f82dba17315d29f2c21e0fd6" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      `ALTER TABLE "vip_codes" ADD CONSTRAINT "FK_67e2cd45678c3f7ea713e96ec5e" FOREIGN KEY ("vip_category_id") REFERENCES "vip_categories"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
    );
  }

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