@Override public void run(final Flyway flyway) { flyway.repair(); } };
@Inject public FlywayExecutor(@Named("report.metadata.store.jdbc") JDBCPoolDataSource config) { Flyway flyway = new Flyway(); flyway.setBaselineOnMigrate(true); flyway.setDataSource(config); flyway.setLocations("db/migration/report"); flyway.setTable("schema_version_report"); try { flyway.migrate(); } catch (FlywayException e) { flyway.repair(); } } }
@Inject public FlywayExecutor(@Named("ui.metadata.jdbc") JDBCConfig config) { Flyway flyway = new Flyway(); flyway.setBaselineOnMigrate(true); flyway.setLocations("db/migration/ui"); flyway.setTable("schema_version_ui"); flyway.setDataSource(config.getUrl(), config.getUsername(), config.getPassword()); try { flyway.migrate(); } catch (FlywayException e) { flyway.repair(); } } }
protected void migrateDatabase() { try { flyway.setTable(FLYWAY_SCHEMA_TABLE_NAME); String url = "jdbc:" + serviceProps.getDatabaseServer(); flyway.setDataSource(url, serviceProps.getDatabaseUsername(), serviceProps.getDatabasePassword()); //Use repair to fix the state if a migration failed and you corrected it. if (serviceProps.getProperty("repairDatabase") != null) { flyway.repair(); } flyway.setValidateOnMigrate(false); flyway.migrate(); } catch (Exception e) { String message = "Error migrating database schema: " + e.getMessage() + " Restart service with options '-repairDatabase true' after the problem" + " has been corrected to resume migration."; logger.error(message); healthCheck.updateStatus(new HealthCheck("migration_failure", HealthCheck.Status.FAIL, message)); try { flywayFailedSemaphore.acquire(); //sleep forever } catch (InterruptedException e1) { } } }
@Override protected Object run(Flyway flyway) { flyway.repair(); return null; } }
@Override public void run(final Flyway flyway) { flyway.repair(); } };
@Override public void run(final Namespace namespace, final Flyway flyway) throws Exception { flyway.repair(); } }
private void repair() { flyway.repair(); }
private void repair() { flyway.repair(); }
private void repair() { flyway.repair(); }
private void repair() { flyway.repair(); }
void migrate(Flyway flyway) { String command = env.getProperty("flyway.commamd", "migrate"); switch (command) { case "migrate": flyway.migrate(); break; case "repair": flyway.repair(); break; default: throw new IllegalArgumentException("Invalid command: " + command); } }
@Override public Integer call() throws Exception { Flyway flyway = getFlyway(); System.out.println("Flyway: repairing datasource " + getDatasource()); flyway.repair(); return 0; } }
protected static void repairDb(String databaseFilePath) throws ClassNotFoundException { if (!databaseFilePath.contains("mv.db")) { databaseFilePath = databaseFilePath + ".mv.db"; } File file = new File(databaseFilePath); if (!file.exists()) { logger.error("File {} doesn't exist", file.getAbsolutePath()); } databaseFilePath = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 6); Flyway flyway = new Flyway(); flyway.setLocations("classpath:migration"); Class.forName("org.h2.Driver"); JdbcDataSource dataSource = new JdbcDataSource(); dataSource.setURL("jdbc:h2:file:" + databaseFilePath); dataSource.setUser("sa"); flyway.setDataSource(dataSource); flyway.repair(); }
@Override public void migrate(Flyway flyway) { try { flyway.migrate(); } catch (FlywayException e) { if (e.getMessage().contains("1.15")) { logger.info("Found failed database migration. Attempting repair"); flyway.repair(); try { flyway.getConfiguration().getDataSource().getConnection().createStatement().executeUpdate("delete from PUBLIC.\"schema_version\" where \"version\" = '1.15' or \"version\" = '1.16'"); } catch (SQLException e1) { logger.error("Error while deleting old migration steps", e); } flyway.migrate(); } else { logger.error("Unable to migrate", e); throw e; } } } };
/** * <p>repair.</p> * * @param uuid a {@link java.lang.String} object. * @return a {@link ameba.util.Result} object. */ @POST @Path("{uuid}/repair") public Result repair(@PathParam("uuid") String uuid) { MigrationFeature.checkMigrationId(uuid); if (failMigrations.isEmpty()) { throw new NotFoundException(); } for (String dbName : failMigrations.keySet()) { MigrationFail fail = failMigrations.get(dbName); fail.flyway.repair(); fail.migration.persist(); fail.migration.reset(); } failMigrations.clear(); return Result.success(); }
final ManagedDataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "flyway-service"); final Flyway flyway = new Flyway(); flyway.setLocations(config.getFlywayFactory().getLocations().get(0)); flyway.setDataSource(dataSource); flyway.repair(); // flyway.migrate(); flyway.clean(); if (flyway.migrate() <= 0) { throw new RuntimeException("migration failed!"); }
private boolean initFlyway(final String url, final String user, final String password){ out.println("[Hibernate Service] Run Flyway"); final Flyway flyway = new Flyway(); flyway.setDataSource(url, user, password); flyway.setCallbacks(new HibernateCallback(out, err)); try { flyway.baseline(); } catch (FlywayException e) { flyway.repair(); } try { flyway.migrate(); } catch (Exception e) { err.println("[Hibernate Service] Flyway Failed"); e.printStackTrace(err); return false; } out.println("[Hibernate Service] Finished Flyway"); return true; }
@Override public void migrate(Flyway flyway) { MigrationInfo current = flyway.info().current(); if (current != null && current.getVersion().equals(INITIAL) && current.getType() == MigrationType.SQL) { logger.info("Detected initial version based on SQL scripts, doing repair to switch to Java based migrations."); flyway.repair(); } flyway.migrate(); } }
private void migrateDbOrError(@NonNull MarquezConfig config) { final Flyway flyway = new Flyway(); final DataSourceFactory database = config.getDataSourceFactory(); flyway.setDataSource(database.getUrl(), database.getUser(), database.getPassword()); // Attempt to perform a database migration. An exception is thrown on failed migration attempts // requiring we handle the throwable and apply a repair on the database to fix any // issues before terminating. try { flyway.migrate(); } catch (FlywayException e) { log.error("Failed to apply migration to database.", e.getMessage()); log.info("Repairing failed database migration...", e.getMessage()); flyway.repair(); log.info("Successfully repaired database, stopping app..."); // The throwable is not propagating up the stack. onFatalError(); // Signal app termination. } }