/// Created by Haoyi on 2023/2/16

part of "migrations.dart";

class _MigrationV2toV3 implements Migration {
  @override
  Future<MigrateResult> migrate(Transaction transaction) async {
    // 由于这里无法保证所在平台是否支持IF NOT EXISTS，所以这里用try catch来处理
    try {
      await transaction
          .execute(
          "ALTER TABLE ${OrderEntity.tbName} ADD ${OrderEntity.dbCategory} TEXT DEFAULT ''");
      await transaction.execute(
          "CREATE INDEX trans_category_idx ON ${OrderEntity.tbName} (${OrderEntity.dbCategory});");
    } catch(error, stacktrace) {
      Log.w("ignore alter cmd!");
    }
    return MigrateResult.success;
  }
}

final migration2to3 = _MigrationV2toV3();
