import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm' /* 번호 대사는 원본 범위를 실제로 읽은 뒤의 최신 상태를 재기동 뒤에도 보존한다. */ const TABLE = 'twin_reference_reconciliations' export class CreateTwinReferenceReconciliations1786800000000 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { if (await queryRunner.hasTable(TABLE)) return const dateType = queryRunner.connection.driver.mappedDataTypes.createDate as string await queryRunner.createTable(new Table({ name: TABLE, columns: [ { name: 'id', type: 'varchar', length: '36', isPrimary: true }, { name: 'domain_id', type: 'varchar', length: '36', isNullable: true }, { name: 'instance_id', type: 'varchar', isNullable: false }, { name: 'scope', type: 'varchar', isNullable: false }, { name: 'status', type: 'varchar', isNullable: false }, { name: 'source_first', type: 'int', isNullable: true }, { name: 'source_last', type: 'int', isNullable: true }, { name: 'cursor_seq', type: 'int', isNullable: true }, { name: 'first_seq_seen', type: 'int', isNullable: true }, { name: 'head_missing', type: 'int', isNullable: true }, { name: 'behind', type: 'int', isNullable: true }, { name: 'reason', type: 'varchar', isNullable: true }, { name: 'checked_at', type: dateType, isNullable: false }, { name: 'created_at', type: dateType, isNullable: true }, { name: 'updated_at', type: dateType, isNullable: true } ] }), true) const table = await queryRunner.getTable(TABLE) if (!table) return await queryRunner.createIndex(table, new TableIndex({ name: 'uq_twin_reference_reconciliation_0', columnNames: ['domain_id', 'instance_id', 'scope'], isUnique: true })) await queryRunner.createIndex(table, new TableIndex({ name: 'ix_twin_reference_reconciliation_0', columnNames: ['domain_id', 'instance_id', 'checked_at'] })) } public async down(queryRunner: QueryRunner): Promise { if (await queryRunner.hasTable(TABLE)) await queryRunner.dropTable(TABLE) } }