本文整理汇总了Java中org.flywaydb.core.Flyway类的典型用法代码示例。如果您正苦于以下问题:Java Flyway类的具体用法?Java Flyway怎么用?Java Flyway使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Flyway类属于org.flywaydb.core包,在下文中一共展示了Flyway类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optimizedDbReset
import org.flywaydb.core.Flyway; //导入依赖的package包/类
private void optimizedDbReset(TestContext testContext, FlywayTest annotation) throws Exception {
if (annotation != null && annotation.invokeCleanDB() && annotation.invokeMigrateDB() && !annotation.invokeBaselineDB()) {
ApplicationContext applicationContext = testContext.getApplicationContext();
FlywayDataSourceContext dataSourceContext = getDataSourceContext(applicationContext, annotation.flywayName());
Flyway flywayBean = ReflectionTestUtils.invokeMethod(this, "getBean", applicationContext, Flyway.class, annotation.flywayName());
if (dataSourceContext != null && flywayBean != null) {
prepareDataSourceContext(dataSourceContext, flywayBean, annotation);
FlywayTest adjustedAnnotation = copyAnnotation(annotation, false, false, true);
ReflectionTestUtils.invokeMethod(this, "dbResetWithAnnotation", testContext, adjustedAnnotation);
return;
}
}
ReflectionTestUtils.invokeMethod(this, "dbResetWithAnnotation", testContext, annotation);
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:21,代码来源:OptimizedFlywayTestExecutionListener.java
示例2: initFlyway
import org.flywaydb.core.Flyway; //导入依赖的package包/类
/**
* Initialise Flyway
*
* @param ds
*/
private void initFlyway(DataSource ds) {
try {
logger.info("Database analysis: in progress...");
Flyway flyway = new Flyway();
flyway.setDataSource(ds);
flyway.setCallbacks(new FlywayCallbackMigration());
flyway.setBaselineOnMigrate(true);
flyway.setValidateOnMigrate(true);
flyway.repair();
flyway.migrate();
logger.info("Database analysis: finish...");
} catch (Exception e) {
logger.error("Database analysis: ERROR", e);
throw e;
}
}
示例3: migrateOrCreateIfNotExists
import org.flywaydb.core.Flyway; //导入依赖的package包/类
public static boolean migrateOrCreateIfNotExists(String dbname) {
String dbpath = getDbPath(dbname);
String jdbcurl = "jdbc:h2:file:" + dbpath + ";DB_CLOSE_ON_EXIT=FALSE";
LOG.info("new jdbcurl = {}", jdbcurl);
Connection conn = null;
try {
conn = DriverManager.getConnection(jdbcurl, "sa", "");
DataSource ds = new CustomFlywayDataSource(new PrintWriter(System.out), conn);
Flyway flyway = new Flyway();
flyway.setDataSource(ds);
// explicitly set h2db driver loaded (= including this jar file) class loader
flyway.setClassLoader(conn.getClass().getClassLoader());
flyway.migrate();
LOG.info("db[{}] migration success", dbname);
// may be already closed -> reconnect.
DbUtils.closeQuietly(conn);
conn = DriverManager.getConnection(jdbcurl, "sa", "");
QueryRunner r = new QueryRunner();
Long cnt = r.query(conn, "select count(*) from PROXY_HISTORY", new ScalarHandler<Long>());
LOG.info("db[{}] open/creation success(select count(*) from logtable returns {})", dbname, cnt);
return true;
} catch (SQLException e) {
LOG.error("db[" + dbname + "] open/migrate/creation error", e);
return false;
} finally {
DbUtils.closeQuietly(conn);
}
}
示例4: migrateFlyway
import org.flywaydb.core.Flyway; //导入依赖的package包/类
@PostConstruct
public void migrateFlyway() {
Flyway flyway = new Flyway();
if (this.nakadiProducerFlywayDataSource != null) {
flyway.setDataSource(nakadiProducerFlywayDataSource);
} else if (this.flywayProperties.isCreateDataSource()) {
flyway.setDataSource(this.flywayProperties.getUrl(), this.flywayProperties.getUser(),
this.flywayProperties.getPassword(),
this.flywayProperties.getInitSqls().toArray(new String[0]));
} else if (this.flywayDataSource != null) {
flyway.setDataSource(this.flywayDataSource);
} else {
flyway.setDataSource(dataSource);
}
flyway.setLocations("classpath:db_nakadiproducer/migrations");
flyway.setSchemas("nakadi_events");
if (callback != null) {
flyway.setCallbacks(callback);
}
flyway.setBaselineOnMigrate(true);
flyway.setBaselineVersionAsString("2133546886.1.0");
flyway.migrate();
}
示例5: cleanMigrateStrategy
import org.flywaydb.core.Flyway; //导入依赖的package包/类
@Bean
public FlywayMigrationStrategy cleanMigrateStrategy() {
FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() {
@Override
public void migrate(Flyway flyway) {
if (clean) {
logger.info("Clean DB with Flyway");
flyway.clean();
} else {
logger.info("Don't clean DB with Flyway");
}
flyway.migrate();
}
};
return strategy;
}
示例6: updateDatabase
import org.flywaydb.core.Flyway; //导入依赖的package包/类
@PostConstruct
public void updateDatabase() throws IOException {
try {
Flyway flyway = new Flyway();
flyway.setEncoding("UTF-8");
flyway.setTable("flyway_schema");
flyway.setLocations("db/migration");
flyway.setSchemas(env.getProperty(PropertyNames.jdbcUser));
flyway.setDataSource(
env.getProperty(PropertyNames.jdbcURL),
env.getProperty(PropertyNames.flywayUser),
env.getProperty(PropertyNames.flywayPassword));
flyway.setBaselineOnMigrate(true);
flyway.migrate();
} catch (Exception e) {
log.error("FAILED TO MIGRATE DATABASE", e);
}
}
示例7: configure
import org.flywaydb.core.Flyway; //导入依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Config $base = conf.getConfig("flyway");
Config $flyway = Try.apply(() -> conf.getConfig(name).withFallback($base))
.orElse($base);
Flyway flyway = new Flyway();
flyway.configure(props($flyway));
if (!$flyway.hasPath("url")) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource dataSource = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
flyway.setDataSource(dataSource);
}
// bind
env.serviceKey()
.generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
// run
Iterable<Command> cmds = commands($flyway);
env.onStart(registry -> {
cmds.forEach(cmd -> cmd.run(flyway));
});
}
示例8: getConnection
import org.flywaydb.core.Flyway; //导入依赖的package包/类
public static Connection getConnection(String dbname) throws SQLException {
String dbpath = getDbPath(dbname);
String jdbcurl = "jdbc:h2:file:" + dbpath + ";DB_CLOSE_ON_EXIT=FALSE";
LOG.info("connect jdbcurl = {}", jdbcurl);
Connection conn = DriverManager.getConnection(jdbcurl, "sa", "");
DataSource ds = new CustomFlywayDataSource(new PrintWriter(System.out), conn);
Flyway flyway = new Flyway();
flyway.setDataSource(ds);
// explicitly set h2db driver loaded (= including this jar file) class loader
flyway.setClassLoader(conn.getClass().getClassLoader());
flyway.migrate();
LOG.info("db[{}] migration success", dbname);
// may be already closed -> reconnect.
DbUtils.closeQuietly(conn);
conn = DriverManager.getConnection(jdbcurl, "sa", "");
return conn;
}
示例9: doMigrate
import org.flywaydb.core.Flyway; //导入依赖的package包/类
public void doMigrate(String table, String location) {
logger.info("migrate : {}, {}", table, location);
Flyway flyway = new Flyway();
flyway.setPlaceholderPrefix("$${");
// flyway.setInitOnMigrate(true);
flyway.setBaselineOnMigrate(true);
// flyway.setInitVersion("0");
flyway.setBaselineVersionAsString("0");
flyway.setDataSource(dataSource);
flyway.setTable(table);
flyway.setLocations(new String[] { location });
try {
flyway.repair();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
flyway.migrate();
}
示例10: prepareDataSourceContext
import org.flywaydb.core.Flyway; //导入依赖的package包/类
private static void prepareDataSourceContext(FlywayDataSourceContext dataSourceContext, Flyway flywayBean, FlywayTest annotation) throws Exception {
if (isAppendable(flywayBean, annotation)) {
dataSourceContext.reload(flywayBean);
} else {
String[] oldLocations = flywayBean.getLocations();
try {
if (annotation.overrideLocations()) {
flywayBean.setLocations(annotation.locationsForMigrate());
} else {
flywayBean.setLocations(ObjectArrays.concat(oldLocations, annotation.locationsForMigrate(), String.class));
}
dataSourceContext.reload(flywayBean);
} finally {
flywayBean.setLocations(oldLocations);
}
}
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:18,代码来源:OptimizedFlywayTestExecutionListener.java
示例11: isAppendable
import org.flywaydb.core.Flyway; //导入依赖的package包/类
/**
* Checks if test migrations are appendable to core migrations.
*/
private static boolean isAppendable(Flyway flyway, FlywayTest annotation) {
if (annotation.overrideLocations()) {
return false;
}
if (ArrayUtils.isEmpty(annotation.locationsForMigrate())) {
return true;
}
MigrationVersion testVersion = findLastVersion(flyway, annotation.locationsForMigrate());
if (testVersion == MigrationVersion.EMPTY) {
return true;
}
MigrationVersion coreVersion = findLastVersion(flyway, flyway.getLocations());
return coreVersion.compareTo(testVersion) < 0;
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:21,代码来源:OptimizedFlywayTestExecutionListener.java
示例12: DBManager
import org.flywaydb.core.Flyway; //导入依赖的package包/类
public DBManager() {
ds = new BasicDataSource();
ds.setDriver(new EmbeddedDriver());
ds.setUrl(Constants.JDBC);
flyway = new Flyway();
flyway.setDataSource(ds);
//flyway.clean();
flyway.migrate();
// just to be sure, try to close
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
LOG.info("Closing DB connection...");
ds.close();
LOG.info("DB closed");
} catch (SQLException ex) {
LOG.error("Error closing DB cconnection", ex);
}
}
});
}
示例13: onStartup
import org.flywaydb.core.Flyway; //导入依赖的package包/类
@PostConstruct
private void onStartup() {
if (dataSource == null) {
log.severe("No datasource found to execute the db migrations!");
throw new EJBException("No datasource found to execute the db migrations!");
}
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setBaselineOnMigrate(true);
for (MigrationInfo i : flyway.info().all()) {
log.log(Level.INFO, "Migrate task: {0} : {1} from file: {2}", new Object[]{i.getVersion(), i.getDescription(), i.getScript()});
}
flyway.migrate();
// aby ustawił kierunki relacji z pliku, odkomentować i ustawić ścieżkę do pliku disp_relations.cfg
// try {
// TempRelationsDirectionsUpdater.run("/home/rdyszlewski/Projekty/wordnetloom3/WordnetLoom/wordnetloom-client/src/main/resources/disp_relations.cfg", dataSource.getConnection());
// } catch (SQLException e) {
// e.printStackTrace();
// }
}
示例14: migrate
import org.flywaydb.core.Flyway; //导入依赖的package包/类
/**
* Migrate the database to the latest available migration.
*/
public void migrate() {
if (this.enabled) {
final Flyway flyway = new Flyway();
flyway.setDataSource(this.dataSource);
if (this.testdata) {
flyway.setLocations(masterDataPath, testDataPath);
} else {
flyway.setLocations(masterDataPath);
}
if (this.clean) {
flyway.clean();
}
flyway.migrate();
}
}
示例15: initDatasource
import org.flywaydb.core.Flyway; //导入依赖的package包/类
public void initDatasource(YadaConfiguration config) throws NamingException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setDatabaseName(config.getString("config/database/dbName"));
dataSource.setUser(config.getString("config/database/user"));
dataSource.setPassword(config.getString("config/database/password"));
dataSource.setServerName(config.getString("config/database/server"));
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
builder.bind("java:comp/env/jdbc/yadatestdb", dataSource);
super.dataSource = dataSource;
builder.activate();
// Database
Flyway flyway = new Flyway();
flyway.setLocations("filesystem:schema"); // Where sql test scripts are stored
flyway.setDataSource(dataSource);
flyway.clean();
flyway.migrate();
}