import { MigrationInterface, QueryRunner, Table } from 'typeorm';
import { Configuration } from '../configuration/configuration.entity';
import { EConfigurationProperty } from '../configuration/helpers/configuration-type.helper';

export class CreateConfigurationTable1625575345999
  implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: 'configuration',
        columns: [
          {
            name: 'id',
            type: 'int',
            isPrimary: true,
            isGenerated: true,
            generationStrategy: 'increment',
            isUnique: true,
          },
          {
            name: 'name',
            type: 'varchar',
            isNullable: false,
          },
          {
            name: 'value',
            type: 'text',
            isNullable: true,
            default: null,
          },
        ],
      })
    );

    const configuration = new Configuration();
    configuration.name = EConfigurationProperty.WORKING_HOURS;
    configuration.value = '-;05:00-14:00;+;+;+;+;-';
    await queryRunner.manager.save(configuration);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable('configuration');
  }
}
