当前位置: 首页>>代码示例>>Java>>正文


Java Flyway.migrate方法代码示例

本文整理汇总了Java中org.flywaydb.core.Flyway.migrate方法的典型用法代码示例。如果您正苦于以下问题:Java Flyway.migrate方法的具体用法?Java Flyway.migrate怎么用?Java Flyway.migrate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.flywaydb.core.Flyway的用法示例。


在下文中一共展示了Flyway.migrate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
	}
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:22,代码来源:JpaConfigEcandidat.java

示例2: 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);
    }
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:33,代码来源:DataStore.java

示例3: 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();
}
 
开发者ID:zalando-nakadi,项目名称:nakadi-producer-spring-boot-starter,代码行数:26,代码来源:FlywayMigrator.java

示例4: 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);
    }
}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:20,代码来源:JdbcConfiguration.java

示例5: 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;
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:21,代码来源:DataStore.java

示例6: 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();
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:22,代码来源:DatabaseMigrator.java

示例7: 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();
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:18,代码来源:YadaTestConfig.java

示例8: 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);
            }
        }
    });
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:25,代码来源:DBManager.java

示例9: onStartup

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@PostConstruct
private void onStartup() throws SQLException {
	if (dataSource == null) {
		LOG.error("no datasource found to execute the db migrations!");
		throw new EJBException(
				"no datasource found to execute the db migrations!");
	}

	String schema = "sql" + FS + "mysql";
	if (DB != null) {
		 schema = "sql" + FS + DB;
	}
	Flyway flyway = new Flyway();
	flyway.setDataSource(dataSource);
	flyway.setBaselineOnMigrate(true);
	flyway.setPlaceholderPrefix("%{");
	flyway.setLocations("sql" + FS + "configdata", schema);
	flyway.setBaselineVersion(MigrationVersion.fromVersion("201609221422"));
	for (MigrationInfo i : flyway.info().all()) {
		LOG.info("migrate task: " + i.getVersion() + " : "
				+ i.getDescription() + " from file: " + i.getScript());
	}
	flyway.repair();
	flyway.migrate();
}
 
开发者ID:witchpou,项目名称:lj-projectbuilder,代码行数:26,代码来源:DataStartupService.java

示例10: contextInitialized

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    Flyway flyway = new Flyway();
    String dataSourceJndi = sc.getInitParameter(FLYWAY_JNDI_DATASOURCE);
    if (dataSourceJndi != null) {
        try {
            DataSource dataSource = (DataSource) new InitialContext().lookup(dataSourceJndi);
            flyway.setDataSource(dataSource);
        } catch (NamingException ex) {
            logger.log(Level.SEVERE, "Error while looking up DataSource", ex);
            // Do not proceed
            return;
        }
    } else {
        String url = sc.getInitParameter(FLYWAY_JDBC_URL);
        String user = sc.getInitParameter(FLYWAY_JDBC_USER);
        String password = sc.getInitParameter(FLYWAY_JDBC_PASSWORD);
        flyway.setDataSource(url, user, password);
    }
    flyway.migrate();
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:23,代码来源:FlywayMigrationServletContextListener.java

示例11: setUpClass

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
  MetaDataTest.setUpClass(h2Url);
  Flyway flyway = new Flyway();
  flyway.setDataSource(dbSchemaUrl, "sa", "");
  flyway.migrate();

  Properties connInfo = new Properties();
  connInfo.setProperty("url", dbSchemaUrl);
  connInfo.setProperty("user", "sa");
  connInfo.setProperty("password", "");

  dbConnection = DriverManager.getConnection(dbSchemaUrl, connInfo);

  Statement stmt = dbConnection.createStatement();
  String sql = "insert into data_sources(name, type, url, ds_set_id, datasource_type) values "
      + "('H2', 'H2', '" + h2Url + "', 1, 'JDBC'); insert into jdbc_sources (id, "
      + "username, password) values(1, 'sa', '');" +
      "update ds_sets set default_datasource_id = 1 where id = 1;";

  stmt.execute(sql);
  stmt.close();
}
 
开发者ID:qubole,项目名称:quark,代码行数:24,代码来源:DbMetaDataTest.java

示例12: setUpClass

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
  MetaDataTest.setUpClass(h2Url);
  Flyway flyway = new Flyway();
  flyway.setDataSource(dbSchemaUrl, "sa", "");
  flyway.migrate();

  Properties connInfo = new Properties();
  connInfo.setProperty("url", dbSchemaUrl);
  connInfo.setProperty("user", "sa");
  connInfo.setProperty("password", "");

  dbConnection = DriverManager.getConnection(dbSchemaUrl, connInfo);

  Statement stmt = dbConnection.createStatement();
  String sql = "insert into ds_sets(id, name) values(10, 'ten'); " +
          "insert into data_sources(name,type, url, ds_set_id, datasource_type) values "
      + "('H2', 'H2', '" + h2Url + "', 10, 'JDBC'); insert into jdbc_sources (id, "
      + "username, password) values(1, 'sa', '');" +
      "update ds_sets set default_datasource_id = 1 where id = 10;";

  stmt.execute(sql);
  stmt.close();
}
 
开发者ID:qubole,项目名称:quark,代码行数:25,代码来源:DSSetMetaDataTest.java

示例13: run

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@Override
public void run(final ServiceRegistryConfiguration configuration, final Environment environment) throws Exception {
    final DataSourceFactory database = configuration.getDatabase();

    // execute DB migrations
    final Flyway flyway = new Flyway();
    flyway.setDataSource(database.getUrl(), database.getUser(), database.getPassword());
    log.debug("execute database migrations");
    flyway.migrate();
    log.info("database migrations successfully executed");

    // create DBI instance
    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, database, "postgresql");

    environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<>(
                    new ServiceRegistryAuthenticator(configuration.getCredentials()), "Realm", ServiceRegistryCaller.class))
    );
    environment.jersey().register(new ServiceResource(jdbi.onDemand(ServiceDAO.class)));
}
 
开发者ID:bitionaire,项目名称:el-bombillo,代码行数:21,代码来源:ServiceRegistryApplication.java

示例14: setUp

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws SQLException, IOException, URISyntaxException,
    ClassNotFoundException {

  String[] args = new String [1];
  args[0] = EndToEndTest.class.getResource("/dbCatalog.json").getPath();
  main = new Main(args);

  new Thread(main).start();

  Flyway flyway = new Flyway();
  flyway.setDataSource(dbUrl, "sa", "");
  flyway.migrate();

  setupTables(dbUrl, "tpcds_db.sql");
  setupTables(h2Url, "tpcds.sql");
  setupTables(cubeUrl, "tpcds_cubes.sql");
  setupTables(viewUrl, "tpcds_views.sql");
}
 
开发者ID:qubole,项目名称:quark,代码行数:20,代码来源:EndToEndTest.java

示例15: setUpDb

import org.flywaydb.core.Flyway; //导入方法依赖的package包/类
@BeforeClass
public static void setUpDb() throws Exception {
  SelectTest.setUpClass(dbUrl);
  Flyway flyway = new Flyway();
  flyway.setDataSource(dbSchemaUrl, "sa", "");
  flyway.migrate();

  Properties connInfo = new Properties();
  connInfo.setProperty("url", dbSchemaUrl);
  connInfo.setProperty("user", "sa");
  connInfo.setProperty("password", "");

  dbConnection = DriverManager.getConnection(dbSchemaUrl, connInfo);

  Statement stmt = dbConnection.createStatement();
  String sql = "insert into data_sources(name, type, url, ds_set_id, datasource_type) values "
      + "('H2', 'H2', '" + dbUrl + "', 1, 'JDBC'); insert into jdbc_sources (id, "
      + "username, password) values(1, 'sa', '');" +
      "update ds_sets set default_datasource_id = 1 where id = 1;";

  stmt.execute(sql);
  stmt.close();
}
 
开发者ID:qubole,项目名称:quark,代码行数:24,代码来源:DbSelectTest.java


注:本文中的org.flywaydb.core.Flyway.migrate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。