import { MigrationInterface, QueryRunner, Table } from 'typeorm';

export class AddJinshujuMatchRules1784700000000 implements MigrationInterface {
  async up(queryRunner: QueryRunner): Promise<void> {
    if (await queryRunner.hasTable('jinshuju_match_rules')) return;

    await queryRunner.createTable(
      new Table({
        name: 'jinshuju_match_rules',
        columns: [
          {
            name: 'id',
            type: 'integer',
            isPrimary: true,
            isGenerated: true,
            generationStrategy: 'increment',
          },
          { name: 'name', type: 'varchar', length: '100' },
          { name: 'form_token', type: 'varchar', length: '64' },
          { name: 'mappings', type: 'text' },
          { name: 'created_at', type: 'datetime', default: 'CURRENT_TIMESTAMP' },
          { name: 'updated_at', type: 'datetime', default: 'CURRENT_TIMESTAMP' },
        ],
      }),
    );
  }

  async down(queryRunner: QueryRunner): Promise<void> {
    if (await queryRunner.hasTable('jinshuju_match_rules')) {
      await queryRunner.dropTable('jinshuju_match_rules');
    }
  }
}
