import { MigrationInterface, QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`SET FOREIGN_KEY_CHECKS=0;`);

    await queryRunner.query(`CREATE TABLE IF NOT EXISTS \`servicereminders\` (
            \`id\` INT(11) NOT NULL AUTO_INCREMENT,
            \`prevOrderId\` INT(11) NOT NULL,
            \`userId\` CHAR(36) NOT NULL,
            \`lastSmsKilometer\` INT(11) NOT NULL DEFAULT 0,
            \`status\` ENUM('new', 'seen', 'called', 'done') NOT NULL DEFAULT 'new',
            \`message\` VARCHAR(255) NULL DEFAULT NULL,
            \`createdAt\` DATETIME NOT NULL,
            PRIMARY KEY (\`id\`),
            INDEX \`fk_servicereminder_orders1_idx\` (\`prevOrderId\` ASC),
            INDEX \`fk_servicereminders_users1_idx\` (\`userId\` ASC),
            CONSTRAINT \`fk_servicereminder_orders1\`
              FOREIGN KEY (\`prevOrderId\`)
              REFERENCES \`orders\` (\`id\`)
              ON DELETE NO ACTION
              ON UPDATE NO ACTION)
          ENGINE = InnoDB
          DEFAULT CHARACTER SET = utf8
          COLLATE = utf8_unicode_ci`);

    await queryRunner.query(`SET FOREIGN_KEY_CHECKS=1;`);
  }

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