import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE \`bonus_credits\`
        ( \`id\` INT NOT NULL AUTO_INCREMENT,
        \`title\` VARCHAR(45) NOT NULL,
        \`userId\` CHAR(36) CHARACTER SET utf8 COLLATE utf8_bin NULL,
        \`code\` VARCHAR(45) NOT NULL,
        \`amount\` INT NOT NULL,
        \`used\` TINYINT NOT NULL DEFAULT '0' , 
        \`createdAt\` DATETIME NOT NULL,
        \`updatedAt\` DATETIME NOT NULL,
        INDEX \`fk_bonus_credits_users1_idx\` (\`userId\` ASC),
        PRIMARY KEY (\`id\`),
        CONSTRAINT \`fk_bonus_credits_users1_idx\`
            FOREIGN KEY (\`userId\`)
            REFERENCES \`users\` (\`id\`)
            ON UPDATE CASCADE,
        UNIQUE (\`code\`))
        ENGINE = InnoDB
        DEFAULT CHARACTER SET = utf8
        COLLATE = utf8_unicode_ci;`,
    );
  }

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