use of org.flywaydb.core.Flyway in project flyway by flyway.
the class Main method main.
/**
* Main method.
*
* @param args The command-line arguments.
*/
public static void main(String[] args) {
Level logLevel = getLogLevel(args);
initLogging(logLevel);
try {
printVersion();
if (isPrintVersionAndExit(args)) {
System.exit(0);
}
List<String> operations = determineOperations(args);
if (operations.isEmpty()) {
printUsage();
return;
}
Properties properties = new Properties();
initializeDefaults(properties);
loadConfiguration(properties, args);
overrideConfiguration(properties, args);
if (!isSuppressPrompt(args)) {
promptForCredentialsIfMissing(properties);
}
dumpConfiguration(properties);
loadJdbcDrivers();
loadJavaMigrationsFromJarDirs(properties);
Flyway flyway = new Flyway();
filterProperties(properties);
flyway.configure(properties);
for (String operation : operations) {
executeOperation(flyway, operation);
}
} catch (Exception e) {
if (logLevel == Level.DEBUG) {
LOG.error("Unexpected error", e);
} else {
if (e instanceof FlywayException) {
LOG.error(e.getMessage());
} else {
LOG.error(e.toString());
}
}
System.exit(1);
}
}
use of org.flywaydb.core.Flyway in project che by eclipse.
the class FlywaySchemaInitializer method init.
@Override
public void init() throws SchemaInitializationException {
try (final Connection conn = dataSource.getConnection()) {
final Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations(locations);
flyway.setClassLoader(Thread.currentThread().getContextClassLoader());
final DbSupport dbSupport = DbSupportFactory.createDbSupport(conn, true);
final String productName = conn.getMetaData().getDatabaseProductName().toLowerCase();
flyway.setResolvers(new CustomSqlMigrationResolver(productName, dbSupport, placeholderReplacer));
flyway.setSkipDefaultResolvers(true);
flyway.setBaselineOnMigrate(baselineOnMigrate);
if (baselineOnMigrate) {
flyway.setBaselineVersionAsString(baselineVersion);
}
flyway.setSqlMigrationSeparator(versionSeparator);
flyway.setSqlMigrationSuffix(scriptsSuffix);
flyway.setSqlMigrationPrefix(scriptsPrefix);
flyway.migrate();
} catch (SQLException | RuntimeException x) {
throw new SchemaInitializationException(x.getLocalizedMessage(), x);
}
}
use of org.flywaydb.core.Flyway in project flyway by flyway.
the class AbstractFlywayMojoSmallTest method execute.
@Test
public void execute() throws Exception {
AbstractFlywayMojo mojo = new AbstractFlywayMojo() {
@Override
protected void doExecute(Flyway flyway) throws Exception {
assertEquals(2, flyway.getSchemas().length);
assertEquals("first", flyway.getSchemas()[0]);
assertEquals("second", flyway.getSchemas()[1]);
}
};
mojo.driver = Driver.class.getName();
mojo.url = "jdbc:h2:mem:dummy";
mojo.user = "sa";
mojo.settings = new DefaultMavenSettingsBuilder().buildSettings();
mojo.mavenProject = new MavenProject();
mojo.mavenProject.setBasedir(new File("."));
mojo.mavenProject.getProperties().setProperty("flyway.schemas", "first,second");
mojo.execute();
}
use of org.flywaydb.core.Flyway in project flyway by flyway.
the class Environment method createFlyway.
/**
* Creates a new Flyway instance.
*
* @return The fully configured Flyway instance.
*/
public static Flyway createFlyway() {
Flyway flyway = new Flyway();
if (runningOnGoogleAppEngine()) {
flyway.setDataSource("jdbc:google:rdbms://flyway-test-project:flywaycloudsql/flyway_cloudsql_db", null, null);
} else {
flyway.setDataSource("jdbc:h2:mem:flyway_db;DB_CLOSE_DELAY=-1", "sa", "");
}
flyway.setLocations("db.migration", "db/more/migrations", "org.flywaydb.sample.migration", "org/flywaydb/sample/webapp/migration");
return flyway;
}
use of org.flywaydb.core.Flyway in project flyway by flyway.
the class Main method main.
/**
* Runs the sample.
*
* @param args None supported.
*/
public static void main(String[] args) throws Exception {
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", "");
flyway.setLocations("db/migration", "org.flywaydb.sample.migration");
flyway.setResolvers(new SampleResolver());
flyway.migrate();
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(flyway.getDataSource());
List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user");
for (Map<String, Object> result : results) {
System.out.println("Name: " + result.get("NAME"));
}
}
Aggregations