Beispiel #1
0
  public void repair() {
    if (!table.existsNoQuotes() && !table.exists()) {
      LOG.info(
          "Repair of metadata table " + table + " not necessary. No failed migration detected.");
      return;
    }

    createIfNotExists();

    try {
      int failedCount =
          jdbcTemplate.queryForInt(
              "SELECT COUNT(*) FROM "
                  + table
                  + " WHERE "
                  + dbSupport.quote("success")
                  + "="
                  + dbSupport.getBooleanFalse());
      if (failedCount == 0) {
        LOG.info(
            "Repair of metadata table " + table + " not necessary. No failed migration detected.");
        return;
      }
    } catch (SQLException e) {
      throw new FlywayException(
          "Unable to check the metadata table " + table + " for failed migrations", e);
    }

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    try {
      jdbcTemplate.execute(
          "DELETE FROM "
              + table
              + " WHERE "
              + dbSupport.quote("success")
              + " = "
              + dbSupport.getBooleanFalse());
    } catch (SQLException e) {
      throw new FlywayException("Unable to repair metadata table " + table, e);
    }

    stopWatch.stop();

    LOG.info(
        "Metadata table "
            + table
            + " successfully repaired (execution time "
            + TimeFormat.format(stopWatch.getTotalTimeMillis())
            + ").");
    LOG.info("Manual cleanup of the remaining effects the failed migration may still be required.");
  }
Beispiel #2
0
  /**
   * Logs the summary of this migration run.
   *
   * @param migrationSuccessCount The number of successfully applied migrations.
   * @param executionTime The total time taken to perform this migration run (in ms).
   */
  private void logSummary(int migrationSuccessCount, long executionTime) {
    if (migrationSuccessCount == 0) {
      LOG.info("Schema " + schema + " is up to date. No migration necessary.");
      return;
    }

    if (migrationSuccessCount == 1) {
      LOG.info(
          "Successfully applied 1 migration to schema "
              + schema
              + " (execution time "
              + TimeFormat.format(executionTime)
              + ").");
    } else {
      LOG.info(
          "Successfully applied "
              + migrationSuccessCount
              + " migrations to schema "
              + schema
              + " (execution time "
              + TimeFormat.format(executionTime)
              + ").");
    }
  }