private static VersionedDatabaseJobHistoryStore findVersionedDatabaseJobHistoryStore(MigrationVersion requiredVersion) throws IllegalAccessException, InstantiationException, ClassNotFoundException { Class<?> foundClazz = null; Class<?> defaultClazz = null; MigrationVersion defaultVersion = MigrationVersion.EMPTY; for (Class<?> clazz : Sets.intersection(reflections.getTypesAnnotatedWith(SupportedDatabaseVersion.class), reflections.getSubTypesOf(VersionedDatabaseJobHistoryStore.class))) { SupportedDatabaseVersion annotation = clazz.getAnnotation(SupportedDatabaseVersion.class); String version = annotation.version(); MigrationVersion actualVersion = MigrationVersion.fromVersion(Strings.isNullOrEmpty(version) ? null : version); if (annotation.isDefault() && actualVersion.compareTo(defaultVersion) > 0) { defaultClazz = clazz; defaultVersion = actualVersion; } if (actualVersion.compareTo(requiredVersion) == 0) { foundClazz = clazz; } } if (foundClazz == null) { foundClazz = defaultClazz; } if (foundClazz == null) { throw new ClassNotFoundException( String.format("Could not find an instance of %s which supports database " + "version %s.", VersionedDatabaseJobHistoryStore.class.getSimpleName(), requiredVersion.toString())); } return (VersionedDatabaseJobHistoryStore) foundClazz.newInstance(); } }
@BeforeClass public static void setUpDatabase() throws Exception { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); database = builder.build(); Flyway flyway = new Flyway(); flyway.setBaselineVersion(MigrationVersion.fromVersion("1.5.2")); flyway.setLocations("classpath:/org/cloudfoundry/identity/uaa/db/hsqldb/"); flyway.setDataSource(database); flyway.migrate(); }
@BeforeClass public static void init() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); database = builder.build(); flyway = new Flyway(); flyway.setBaselineVersion(MigrationVersion.fromVersion("1.5.2")); flyway.setLocations("classpath:/org/cloudfoundry/identity/uaa/db/hsqldb/"); flyway.setDataSource(database); flyway.migrate(); }
@Override public MigrationVersion getVersion() { if (this.version == null) { String temp = getSpincastFlywayMigration().getClass().getSimpleName(); if (!temp.startsWith("M_")) { throw new RuntimeException("Invalid migration class name. Must start with 'M_' followed by the version. " + "For example: 'M_2018_09_18_00' or 'M_1_44_0__someDescription'."); } temp = temp.substring("M_".length()); //========================================== // Suffixe to remove? //========================================== int pos = temp.indexOf("__"); if (pos > -1) { temp = temp.substring(0, pos); } this.version = MigrationVersion.fromVersion(temp); } return this.version; }
public AppliedMigration mapRow(final ResultSet rs) throws SQLException { Integer checksum = rs.getInt("checksum"); if (rs.wasNull()) { checksum = null; } return new AppliedMigration( rs.getInt("version_rank"), rs.getInt("installed_rank"), MigrationVersion.fromVersion(rs.getString("version")), rs.getString("description"), MigrationType.valueOf(rs.getString("type")), rs.getString("script"), checksum, rs.getTimestamp("installed_on"), rs.getString("installed_by"), rs.getInt("execution_time"), rs.getBoolean("success") ); } });
flyway.setBaselineVersion(MigrationVersion.fromVersion(flywayBaselineVersion)); flyway.setTarget(MigrationVersion.fromVersion(targetVersion)); } else {
private static VersionedDatabaseJobHistoryStore findVersionedDatabaseJobHistoryStore(MigrationVersion requiredVersion) throws IllegalAccessException, InstantiationException, ClassNotFoundException { Class<?> foundClazz = null; Class<?> defaultClazz = null; MigrationVersion defaultVersion = MigrationVersion.EMPTY; for (Class<?> clazz : Sets.intersection(reflections.getTypesAnnotatedWith(SupportedDatabaseVersion.class), reflections.getSubTypesOf(VersionedDatabaseJobHistoryStore.class))) { SupportedDatabaseVersion annotation = clazz.getAnnotation(SupportedDatabaseVersion.class); String version = annotation.version(); MigrationVersion actualVersion = MigrationVersion.fromVersion(Strings.isNullOrEmpty(version) ? null : version); if (annotation.isDefault() && actualVersion.compareTo(defaultVersion) > 0) { defaultClazz = clazz; defaultVersion = actualVersion; } if (actualVersion.compareTo(requiredVersion) == 0) { foundClazz = clazz; } } if (foundClazz == null) { foundClazz = defaultClazz; } if (foundClazz == null) { throw new ClassNotFoundException( String.format("Could not find an instance of %s which supports database " + "version %s.", VersionedDatabaseJobHistoryStore.class.getSimpleName(), requiredVersion.toString())); } return (VersionedDatabaseJobHistoryStore) foundClazz.newInstance(); } }
SupportedDatabaseVersion annotation = clazz.getAnnotation(SupportedDatabaseVersion.class); String version = annotation.version(); MigrationVersion actualVersion = MigrationVersion.fromVersion(Strings.isNullOrEmpty(version) ? null : version); if (annotation.isDefault() && actualVersion.compareTo(defaultVersion) > 0) { defaultClazz = clazz;
@Bean(initMethod = "migrate") Flyway flyway() { Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setLocations("classpath:/flyway"); flyway.setBaselineVersion(MigrationVersion.fromVersion("5.0.0.0")); try { flyway.baseline(); } catch (FlywayException e) { log.warn("Database is already baselined with flyway"); } return flyway; } }
flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setBaselineDescription("schema creation called on application context by topia flyway service"); flyway.baseline();
int.class) == 0) { logger.info("H2 database not found, creating new schema and populate with default data"); flyway.setBaselineVersion(MigrationVersion.fromVersion(DB_SETUP_VERSION)); flyway.setBaselineOnMigrate(true); try { int.class) == 0) { logger.info("Flyway's DB migration not setup in this version, set baseline version to 0.5.0"); flyway.setBaselineVersion(MigrationVersion.fromVersion("0.5.0")); flyway.setBaselineOnMigrate(true);
protected Flyway createFlyway(OrmContext oc) { Set<String> locations = new LinkedHashSet<>(); for(Resource dir : cfg.getDirs(cfg.getMigrationName())){ if(null != dir && dir.exists()) { if (dir.hasClasspath()) { locations.add(dir.getClasspath()); } else { locations.add("filesystem:" + dir.getFilepath()); } } } Resource cp = Resources.getResource("classpath:db/migration/"); if(cp.exists()) { locations.add("db/migration"); } if(locations.isEmpty()) { return null; } Flyway flyway = new Flyway(); flyway.setResolvers(); flyway.setBaselineVersion(MigrationVersion.fromVersion("0")); flyway.setCallbacks(new FlywayMigrateCallback()); flyway.setLocations(locations.toArray(new String[0])); flyway.setDataSource(oc.getDataSource()); flyway.setValidateOnMigrate(false); return flyway; }
@SuppressFBWarnings( value = { "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", "ODR_OPEN_DATABASE_RESOURCE", }, justification = "Ignore that jdbcTemplate methods might return null or that the DB connection may be left open." ) @Before public void beforeEach() throws Exception { canaries = encryptionKeyCanaryRepository.findAll(); databaseName = jdbcTemplate.getDataSource() .getConnection() .getMetaData() .getDatabaseProductName() .toLowerCase(); flyway.clean(); flyway.setTarget(MigrationVersion.fromVersion("40")); flyway.migrate(); }
@Before public void beforeEach() { canaries = encryptionKeyCanaryRepository.findAll(); flyway.clean(); flyway.setTarget(MigrationVersion.fromVersion("4")); flyway.migrate(); }
/** * {@inheritDoc} */ @Override public Collection<ResolvedMigration> resolveMigrations() { List<ResolvedMigration> resolvedMigrations = Lists.newArrayList(); ScriptInfo info = migration.generate(); if (info != null) { ResolvedMigrationImpl migration = new ResolvedMigrationImpl(); migration.setVersion(MigrationVersion.fromVersion(info.getRevision())); migration.setDescription(info.getDescription()); migration.setScript(info.getRevision() + "__" + toUnderScore(info.getDescription()) + ".sql"); migration.setChecksum(calculateChecksum("-- " + info.getRevision() + "\r\n" + info.getApplyDdl())); migration.setType(MigrationType.SQL); migration.setExecutor(new SqlMigrationExecutor(info)); resolvedMigrations.add(migration); } return resolvedMigrations; }
flyway.setInitVersion(MigrationVersion.fromVersion("1")); flyway.setInitVersion(MigrationVersion.fromVersion("0"));
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath, boolean validateOnMigrate) { Flyway flyway = new Flyway(); String location = "filesystem:" + scriptRootPath + File.separator + conf.getDbType(); flyway.setEncoding(encoding); flyway.setTable(metaDataTableName); flyway.setSqlMigrationPrefix(sqlMigrationPrefix); flyway.setValidateOnMigrate(validateOnMigrate); flyway.setOutOfOrder(outOfOrder); flyway.setBaselineOnMigrate(baselineOnMigrate); flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setCleanOnValidationError(cleanOnValidationError); flyway.setLocations(location); flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null); return flyway; }
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath, boolean validateOnMigrate) { Flyway flyway = new Flyway(); String location = "filesystem:" + scriptRootPath + File.separator + conf.getDbType(); flyway.setEncoding(encoding); flyway.setTable(metaDataTableName); flyway.setSqlMigrationPrefix(sqlMigrationPrefix); flyway.setValidateOnMigrate(validateOnMigrate); flyway.setOutOfOrder(outOfOrder); flyway.setBaselineOnMigrate(baselineOnMigrate); flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setCleanOnValidationError(cleanOnValidationError); flyway.setLocations(location); flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null); return flyway; }
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath) { Flyway flyway = new Flyway(); String location = "filesystem:" + scriptRootPath; flyway.setEncoding(encoding); flyway.setTable(metaDataTableName); flyway.setValidateOnMigrate(validateOnMigrate); flyway.setOutOfOrder(outOfOrder); flyway.setBaselineOnMigrate(baselineOnMigrate); flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setCleanOnValidationError(cleanOnValidationError); flyway.setLocations(location); flyway.setResolvers(new ShellMigrationResolver(flyway.getConfiguration(), location, shellMigrationPrefix, shellMigrationSeperator, shellMigrationSuffix)); flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null); return flyway; }
public static Flyway get(StorageProviderConfiguration conf, String scriptRootPath) { Flyway flyway = new Flyway(); String location = "filesystem:" + scriptRootPath; flyway.setEncoding(encoding); flyway.setTable(metaDataTableName); flyway.setValidateOnMigrate(validateOnMigrate); flyway.setOutOfOrder(outOfOrder); flyway.setBaselineOnMigrate(baselineOnMigrate); flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setCleanOnValidationError(cleanOnValidationError); flyway.setLocations(location); flyway.setResolvers(new ShellMigrationResolver(flyway.getConfiguration(), location, shellMigrationPrefix, shellMigrationSeperator, shellMigrationSuffix)); flyway.setDataSource(conf.getUrl(), conf.getUser(), conf.getPassword(), null); return flyway; }