Examples of Flyway


Examples of org.flywaydb.core.Flyway

        if (flywaydb==null)
        {
            try(Connection connection = datasource.getConnection())
            {
                // Initialize Flyway DB API (http://flywaydb.org/), used to perform DB migrations
                flywaydb = new Flyway();
                flywaydb.setDataSource(datasource);
                flywaydb.setEncoding("UTF-8");

                // Migration scripts are based on DBMS Keyword (see full path below)
                DatabaseMetaData meta = connection.getMetaData();
View Full Code Here

Examples of org.flywaydb.core.Flyway

            throws SQLException
    {
        try
        {
            // Setup Flyway API against our database
            Flyway flyway = setupFlyway(datasource);

            // Set whethe Flyway will run migrations "out of order". By default, this is false,
            // and Flyway ONLY runs migrations that have a higher version number.
            flyway.setOutOfOrder(outOfOrder);

            // If a target version was specified, tell Flyway to ONLY migrate to that version
            // (i.e. all later migrations are left as "pending"). By default we always migrate to latest version.
            if(!StringUtils.isBlank(targetVersion))
            {
                flyway.setTarget(targetVersion);
            }

            // Does the necessary Flyway table ("schema_version") exist in this database?
            // If not, then this is the first time Flyway has run, and we need to initialize
            // NOTE: search is case sensitive, as flyway table name is ALWAYS lowercase,
            // See: http://flywaydb.org/documentation/faq.html#case-sensitive
            if(!tableExists(connection, flyway.getTable(), true))
            {
                // Try to determine our DSpace database version, so we know what to tell Flyway to do
                String dbVersion = determineDBVersion(connection);

                // If this is a fresh install, dbVersion will be null
                if (dbVersion==null)
                {
                    // Initialize the Flyway database table with defaults (version=1)
                    flyway.init();
                }
                else
                {
                    // Otherwise, pass our determined DB version to Flyway to initialize database table
                    flyway.setInitVersion(dbVersion);
                    flyway.setInitDescription("Initializing from DSpace " + dbVersion + " database schema");
                    flyway.init();
                }
            }

            // Determine pending Database migrations
            MigrationInfo[] pending = flyway.info().pending();

            // As long as there are pending migrations, log them and run migrate()
            if (pending!=null && pending.length>0)
            {
                log.info("Pending DSpace database schema migrations:");
                for (MigrationInfo info : pending)
                {
                    log.info("\t" + info.getVersion() + " " + info.getDescription() + " " + info.getType() + " " + info.getState());
                }

                // Run all pending Flyway migrations to ensure the DSpace Database is up to date
                flyway.migrate();

                // Flag that Discovery will need reindexing, since database was updated
                setReindexDiscovery(true);
            }
            else
View Full Code Here

Examples of org.flywaydb.core.Flyway

    }

    @Bean(initMethod = "migrate")
    @ConfigurationProperties(prefix = "flyway")
    public Flyway flyway() {
      Flyway flyway = new Flyway();
      if (this.properties.isCreateDataSource()) {
        flyway.setDataSource(this.properties.getUrl(), this.properties.getUser(),
            this.properties.getPassword(), this.properties.getInitSqls()
                .toArray(new String[0]));
      }
      else if (this.flywayDataSource != null) {
        flyway.setDataSource(this.flywayDataSource);
      }
      else {
        flyway.setDataSource(this.dataSource);
      }
      return flyway;
    }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  public void createDataSource() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context,
        "flyway.url:jdbc:hsqldb:mem:flywaytest", "flyway.user:sa");
    registerAndRefresh(EmbeddedDataSourceConfiguration.class,
        FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertNotNull(flyway.getDataSource());
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  @Test
  public void flywayDataSource() throws Exception {
    registerAndRefresh(FlywayDataSourceConfiguration.class,
        EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class,
        PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertNotNull(flyway.getDataSource());
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  @Test
  public void defaultFlyway() throws Exception {
    registerAndRefresh(EmbeddedDataSourceConfiguration.class,
        FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertEquals("[classpath:db/migration]", Arrays.asList(flyway.getLocations())
        .toString());
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  public void overrideLocations() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context,
        "flyway.locations:classpath:db/changelog,classpath:db/migration");
    registerAndRefresh(EmbeddedDataSourceConfiguration.class,
        FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertEquals("[classpath:db/changelog, classpath:db/migration]",
        Arrays.asList(flyway.getLocations()).toString());
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  @Test
  public void overrideSchemas() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "flyway.schemas:public");
    registerAndRefresh(EmbeddedDataSourceConfiguration.class,
        FlywayAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    Flyway flyway = this.context.getBean(Flyway.class);
    assertEquals("[public]", Arrays.asList(flyway.getSchemas()).toString());
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

  private Map<String, Flyway> flyways() {
    Map<String, Flyway> flywayMap = Maps.newHashMap();
    Map<String, DbSource> dbSourceMap = dbConfig.getAllDbSources();
    DbSource dbSource = null;
    String migrationFilesLocation = null;
    Flyway flyway = null;
    for (String dbName : dbSourceMap.keySet()) {
      migrationFilesLocation = flywayPrefixToMigrationScript + dbName;
//      if (dbConfig.migrationFileDirectoryExists(migrationFilesLocation)) {
      dbSource = dbSourceMap.get(dbName);
      flyway = new Flyway();
      flyway.setDataSource(dbSource.url, dbSource.user, dbSource.password);
      flyway.setLocations(migrationFilesLocation);
      if (dbConfig.isClean(dbName)) {
        flyway.setCleanOnValidationError(true);
      }
      if (dbConfig.initOnMigrate(dbName)) {
        flyway.setInitOnMigrate(true);
      }
      flywayMap.put(dbName, flyway);
//      }
    }
    return flywayMap;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.