Examples of Flyway


Examples of com.googlecode.flyway.core.Flyway

    public void upgradeAllTenants() {
  upgradeTenantDB();
        final List<MifosPlatformTenant> tenants = this.tenantDetailsService.findAllTenants();
        for (final MifosPlatformTenant tenant : tenants) {
            if (tenant.isAutoUpdateEnabled()) {
                final Flyway flyway = new Flyway();
                flyway.setDataSource(tenant.databaseURL(), tenant.getSchemaUsername(), tenant.getSchemaPassword());
                flyway.setLocations("sql/migrations/core_db");
                flyway.setOutOfOrder(true);
                try {
      flyway.migrate();
                } catch (FlywayException e) {
          String betterMessage = e.getMessage()
              + "; for Tenant DB URL: " + tenant.databaseURL()
              + ", username: " + tenant.getSchemaUsername();
          throw new FlywayException(betterMessage, e.getCause());
View Full Code Here

Examples of com.googlecode.flyway.core.Flyway

  /**
   * Initializes, and if required upgrades (using Flyway) the Tenant DB itself.
   */
  private void upgradeTenantDB() {
    final Flyway flyway = new Flyway();
    flyway.setDataSource(tenantDataSource);
    flyway.setLocations("sql/migrations/list_db");
    flyway.setOutOfOrder(true);
    flyway.migrate();

    tenantDataSourcePortFixService.fixUpTenantsSchemaServerPort();
  }
View Full Code Here

Examples of com.googlecode.flyway.core.Flyway

public class DatabaseMigrator {

    private final Flyway flyway;

    public DatabaseMigrator(DataSource dataSource) {
        flyway = new Flyway();
        flyway.setDataSource(dataSource);
        flyway.setSqlMigrationPrefix("");
        silenceLogging();
    }
View Full Code Here

Examples of com.googlecode.flyway.core.Flyway

import com.googlecode.flyway.core.Flyway;

public class FlywayDemo1 {
  public static void main(String[] args)
  {
    Flyway flyway = new Flyway();
    flyway.setDataSource(getDataSource());
    flyway.setSchemas("demo1");
    flyway.init();
   
    System.out.println("+++ DEMO END");
  }
View Full Code Here

Examples of com.googlecode.flyway.core.Flyway

public class FlywayDemo3
{
  public static void main(String[] args)
  {
    Flyway flyway = new Flyway();
    flyway.setDataSource(getDataSource());
    flyway.setSchemas("demo2");
    flyway.migrate();
   
    System.out.println("+++ DEMO END");
  }
View Full Code Here

Examples of com.googlecode.flyway.core.Flyway

public class FlywayDemo4
{
  public static void main(String[] args)
  {
    Flyway flyway = new Flyway();
    flyway.setDataSource(getDataSource());
    flyway.setSchemas("demo3");
    flyway.migrate();
   
    System.out.println("+++ DEMO END");
  }
View Full Code Here

Examples of org.flywaydb.core.Flyway

            loadConfigurationFile(properties, args);
            overrideConfiguration(properties, args);

            loadJdbcDriversAndJavaMigrations(properties);

            Flyway flyway = new Flyway();
            flyway.configure(properties);
            RepeatableFlyway.configure(flyway, properties);

            int consoleWidth = PropertiesUtils.getIntProperty(properties, "flyway.consoleWidth", 80);

            for (String operation : operations) {
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

Examples of org.flywaydb.core.Flyway

        }

        if ("true".equals(applicationProperties.getProperty("dbmigrate.clean"))) {
            logger.info("clean database");

            Flyway flyway = new Flyway();
            flyway.setDataSource(dataSource);
            flyway.clean();
        }

        Collection<DatabaseMigrateInfo> databaseMigrateInfos = new DatabaseMigrateInfoBuilder(
                applicationProperties).build();

        for (DatabaseMigrateInfo databaseMigrateInfo : databaseMigrateInfos) {
            if (!databaseMigrateInfo.isEnabled()) {
                logger.info("skip migrate : {}, {}, {}",
                        databaseMigrateInfo.getName(),
                        databaseMigrateInfo.getTable(),
                        databaseMigrateInfo.getLocation());

                continue;
            }

            logger.info("migrate : {}, {}, {}", databaseMigrateInfo.getName(),
                    databaseMigrateInfo.getTable(),
                    databaseMigrateInfo.getLocation());

            Flyway flyway = new Flyway();
            flyway.setPlaceholderPrefix("$${");
            flyway.setInitOnMigrate(true);
            flyway.setInitVersion("0");
            flyway.setDataSource(dataSource);
            flyway.setTable(databaseMigrateInfo.getTable());
            flyway.setLocations(new String[] { databaseMigrateInfo
                    .getLocation() });
            flyway.migrate();
        }
    }
View Full Code Here

Examples of org.flywaydb.core.Flyway

            // Get configured DB URL for reporting below
            String url = ConfigurationManager.getProperty("db.url");

            // Point Flyway API to our database
            Flyway flyway = setupFlyway(dataSource);

            // "test" = Test Database Connection
            if(argv[0].equalsIgnoreCase("test"))
            {
                // Try to connect to the database
                System.out.println("\nAttempting to connect to database using these configurations: ");
                System.out.println(" - URL: " + url);
                System.out.println(" - Driver: " + ConfigurationManager.getProperty("db.driver"));
                System.out.println(" - Username: " + ConfigurationManager.getProperty("db.username"));
                System.out.println(" - Password: [hidden]");
                System.out.println(" - Schema: " + ConfigurationManager.getProperty("db.schema"));
                System.out.println("\nTesting connection...");
                try
                {
                    // Just do a high level test by getting our configured DataSource and attempting to connect to it
                    // NOTE: We specifically do NOT call DatabaseManager.getConnection() because that will attempt
                    // a full initialization of DatabaseManager & also cause database migrations/upgrades to occur
                    Connection connection = dataSource.getConnection();
                    connection.close();
                }
                catch (SQLException sqle)
                {
                    System.err.println("\nError: ");
                    System.err.println(" - " + sqle);
                    System.err.println("\nPlease see the DSpace documentation for assistance.\n");
                    System.exit(1);
                }

                System.out.println("Connected successfully!\n");
            }
            // "info" = Basic Database Information
            else if(argv[0].equalsIgnoreCase("info"))
            {
                // Get basic Database info
                Connection connection = dataSource.getConnection();
                DatabaseMetaData meta = connection.getMetaData();
                System.out.println("\nDatabase URL: " + url);
                System.out.println("Database Schema: " + getSchemaName(connection));
                System.out.println("Database Software: " + meta.getDatabaseProductName() + " version " + meta.getDatabaseProductVersion());
                System.out.println("Database Driver: " + meta.getDriverName() + " version " + meta.getDriverVersion());

                // Get info table from Flyway
                System.out.println("\n" + MigrationInfoDumper.dumpToAsciiTable(flyway.info().all()));

                // If Flyway is NOT yet initialized, also print the determined version information
                // 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))
                {
                    System.out.println("\nNOTE: This database is NOT yet initialized for auto-migrations (via Flyway).");
                    // Determine which version of DSpace this looks like
                    String dbVersion = determineDBVersion(connection);
                    if (dbVersion!=null)
                    {
                        System.out.println("\nYour database looks to be compatible with DSpace version " + dbVersion);
                        System.out.println("All upgrades *after* version " + dbVersion + " will be run during the next migration.");
                        System.out.println("\nIf you'd like to upgrade now, simply run 'dspace database migrate'.");
                    }
                }
                connection.close();
            }
            // "migrate" = Manually run any outstanding Database migrations (if any)
            else if(argv[0].equalsIgnoreCase("migrate"))
            {
                System.out.println("\nDatabase URL: " + url);

                // "migrate" allows for an OPTIONAL second argument:
                //    - "ignored" = Also run any previously "ignored" migrations during the migration
                //    - [version] = ONLY run migrations up to a specific DSpace version (ONLY FOR TESTING)
                if(argv.length==2)
                {
                    if(argv[1].equalsIgnoreCase("ignored"))
                    {
                        System.out.println("Migrating database to latest version AND running previously \"Ignored\" migrations... (Check logs for details)");
                        Connection connection = dataSource.getConnection();
                        // Update the database to latest version, but set "outOfOrder=true"
                        // This will ensure any old migrations in the "ignored" state are now run
                        updateDatabase(dataSource, connection, null, true);
                        connection.close();
                    }
                    else
                    {
                        // Otherwise, we assume "argv[1]" is a valid migration version number
                        // This is only for testing! Never specify for Production!
                        System.out.println("Migrating database ONLY to version " + argv[1] + " ... (Check logs for details)");
                        System.out.println("\nWARNING: It is highly likely you will see errors in your logs when the Metadata");
                        System.out.println("or Bitstream Format Registry auto-update. This is because you are attempting to");
                        System.out.println("use an OLD version " + argv[1] + " Database with a newer DSpace API. NEVER do this in a");
                        System.out.println("PRODUCTION scenario. The resulting old DB is only useful for migration testing.\n");
                        Connection connection = dataSource.getConnection();
                        // Update the database, to the version specified.
                        updateDatabase(dataSource, connection, argv[1], false);
                        connection.close();
                    }
                }
                else
                {
                    System.out.println("Migrating database to latest version... (Check logs for details)");
                    // NOTE: This looks odd, but all we really need to do is ensure the
                    // DatabaseManager auto-initializes. It'll take care of the migration itself.
                    // Asking for our DB Name will ensure DatabaseManager.initialize() is called.
                    DatabaseManager.getDbName();
                }
                System.out.println("Done.");
            }
            // "repair" = Run Flyway repair script
            else if(argv[0].equalsIgnoreCase("repair"))
            {
                System.out.println("\nDatabase URL: " + url);
                System.out.println("Attempting to repair any previously failed migrations via FlywayDB... (Check logs for details)");
                flyway.repair();
                System.out.println("Done.");
            }
            // "clean" = Run Flyway clean script
            else if(argv[0].equalsIgnoreCase("clean"))
            {
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.