org.flywaydb.core.api.MigrationInfoService Java Examples
The following examples show how to use
org.flywaydb.core.api.MigrationInfoService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreviewMigrateCommand.java From keywhiz with Apache License 2.0 | 6 votes |
@Override protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception { DataSource dataSource = config.getDataSourceFactory() .build(new MetricRegistry(), "migration-preview-datasource"); Flyway flyway = Flyway.configure().dataSource(dataSource).locations(config.getMigrationsDir()).table(config.getFlywaySchemaTable()).load(); MigrationInfoService info = flyway.info(); MigrationInfo current = info.current(); if (current == null) { logger.info("No migrations have been run yet."); } else { logger.info("Currently applied migration:"); logger.info("* {} - {}", current.getVersion(), current.getDescription()); } if (info.pending().length > 0) { logger.info("Pending migrations:"); for (MigrationInfo migration : info.pending()) { logger.info("* {} - {}", migration.getVersion(), migration.getDescription()); } } else { logger.info("No pending migrations"); } }
Example #2
Source File: DatabaseJobHistoryStore.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private static MigrationVersion getDatabaseVersion(DataSource dataSource) throws FlywayException { Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); MigrationInfoService info = flyway.info(); MigrationVersion currentVersion = MigrationVersion.EMPTY; if (info.current() != null) { currentVersion = info.current().getVersion(); } return currentVersion; }
Example #3
Source File: StatisticsFlywayWrapper.java From sailfish-core with Apache License 2.0 | 2 votes |
public void init(HibernateStorageSettings settings) { try { readWriteLock.writeLock().lock(); migrationRequired = false; sfUpdateRequired = false; flyway = new Flyway(); flyway.getPlaceholders().put("db_name", settings.getDbName()); String[] initSqls = new String[0]; if (settings.getDbms().equals(DbmsType.PostgreSQL.getValue())) { flyway.setLocations(PSQL_SCRIPT_LOCATION); } if (settings.getDbms().equals(DbmsType.MySql.getValue())) { flyway.setLocations(MYSQL_SCRIPT_LOCATION); initSqls = MYSQL_INIT_SQL; } flyway.setDataSource(settings.buildConnectionUrl(), settings.getUsername(), settings.getPassword(), initSqls); flyway.setBaselineOnMigrate(false); // Get info about migrations MigrationInfoService info = flyway.info(); currentDbVersionInfo = info.current(); pendingMigrationsInfo = info.pending(); MigrationInfo[] all = info.all(); // Checks if (currentDbVersionInfo == null) { migrationRequired = true; throw new OlderSchemaException("DB initialization is required"); } if (pendingMigrationsInfo.length != 0) { migrationRequired = true; throw new OlderSchemaException("Migration to version " + pendingMigrationsInfo[pendingMigrationsInfo.length - 1].getVersion().getVersion() + " is required"); } if (all.length != 0) { MigrationInfo lastKnown = all[all.length - 1]; if(lastKnown.getState() == MigrationState.FUTURE_SUCCESS) { sfUpdateRequired = true; throw new NewerSchemaException("DB schema has newer version " + lastKnown.getVersion().getVersion() + ". Upgrade this Sailfish instance to use it."); } } } finally { readWriteLock.writeLock().unlock(); } }