private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
/** * Returns a Sqlg configuration (Apache Commons) based on the supplied Flyway configuration. */ protected org.apache.commons.configuration.Configuration sqlgConfiguration(Configuration configuration) { Map<String, Object> result = new LinkedHashMap<>(); // The most important part is getting the JDBC URL since that is required by Sqlg result.put(SqlgGraph.JDBC_URL, JdbcUrlDataSource.unwrap(configuration.getDataSource()).getJdbcUrl()); // Abuse the Flyway place holders as extra configuration parameters for Sqlg result.putAll(configuration.getPlaceholders()); return new MapConfiguration(result); }
/** * Return a Sqlg dialect based on the supplied Flyway configuration. */ protected SqlDialect sqlDialect(Configuration configuration) { // Mimic what Sqlg does to load a dialect String connectionUri = JdbcUrlDataSource.unwrap(configuration.getDataSource()).getJdbcUrl(); for (SqlgPlugin p : ServiceLoader.load(SqlgPlugin.class, SqlgGraph.class.getClassLoader())) { if (p.getDriverFor(connectionUri) != null) { return p.instantiateDialect(); } } throw new IllegalStateException("Unable to determine Sqlg dialect to use for JDBC URL: " + connectionUri); }
@Override protected void run(final Namespace namespace, final Flyway flyway) throws Exception { final Boolean namespaceBoolean = namespace.getBoolean(OUT_OF_ORDER); final Boolean cleanOnValidationError = namespace.getBoolean(CLEAN_ON_VALIDATION_ERROR); FluentConfiguration config = Flyway.configure(flyway.getConfiguration().getClassLoader()).configuration(flyway.getConfiguration()); if (namespaceBoolean != null) { config.outOfOrder(namespaceBoolean); } if (cleanOnValidationError != null) { config.cleanOnValidationError(cleanOnValidationError); } Flyway customFlyway = config.load(); customFlyway.validate(); } }
@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; } } } };
final Boolean baselineOnMigrate = namespace.getBoolean(INIT_ON_MIGRATE); FluentConfiguration config = Flyway.configure(flyway.getConfiguration().getClassLoader()).configuration(flyway.getConfiguration());
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
@SuppressWarnings("unused") @TaskAction public Object runTask() { try { Map<String, String> envVars = ConfigUtils.environmentVariablesToPropertyMap(); Set<URL> extraURLs = new HashSet<>(); if (isJavaProject()) { addClassesAndResourcesDirs(extraURLs); addConfigurationArtifacts(determineConfigurations(envVars), extraURLs); } ClassLoader classLoader = new URLClassLoader( extraURLs.toArray(new URL[0]), getProject().getBuildscript().getClassLoader()); Flyway flyway = Flyway.configure(classLoader).configuration(createFlywayConfig(envVars)).load(); Object result = run(flyway); ((DriverDataSource) flyway.getConfiguration().getDataSource()).shutdownDatabase(); return result; } catch (Exception e) { throw new FlywayException(collectMessages(e, "Error occurred while executing " + getName()), e); } }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }
private boolean isMigrationAvailable() { return Arrays.stream(flyway.getConfiguration().getLocations()) .anyMatch(l-> { if (l.isClassPath()) { return Thread.currentThread().getContextClassLoader().getResource(l.getPath()) != null; } else if (l.isFileSystem()){ return Files.exists(Paths.get(l.getPath())); } else throw new UnreachableException(); }); }
private String[] convertLocationToString(Flyway flyWay) { Location[] locations = flyWay.getConfiguration().getLocations(); String [] stringLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { stringLocations[i] = locations[i].getDescriptor(); } return stringLocations; }