@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(); }
@Override public void afterEachMigrate(Connection connection, MigrationInfo info) { super.afterEachMigrate(connection, info); try { connection.commit(); } catch (SQLException e) { Assert.fail(e.getMessage()); } for (MigrationTest test : tests) { if (test.getTargetMigration().equals(info.getVersion().getVersion())) { try { test.runAssertions(); } catch (Exception e) { Assert.fail(e.getMessage()); } assertionsRan[0]++; } } } });
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(); } }
String version = last.getVersion().getVersion(); flyway.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion)); flyway.setBaselineDescription("schema creation called on application context by topia flyway service"); flyway.baseline();
@Override public void addAppliedMigration(final AppliedMigration appliedMigration) { final MigrationVersion version = appliedMigration.getVersion(); final String versionStr = version == null ? null : version.toString(); final int calculateInstalledRank; try {
/** * Checks if test migrations are appendable to core migrations. */ protected static boolean isAppendable(Flyway flyway, FlywayTest annotation) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { if (annotation.overrideLocations()) { return false; } if (ArrayUtils.isEmpty(annotation.locationsForMigrate())) { return true; } MigrationVersion testVersion = findFirstVersion(flyway, annotation.locationsForMigrate()); if (testVersion == MigrationVersion.EMPTY) { return true; } MigrationVersion coreVersion = findLastVersion(flyway, getFlywayLocations(flyway)); return coreVersion.compareTo(testVersion) < 0; }
/** * {@inheritDoc} * @see org.flywaydb.core.api.callback.FlywayCallback#beforeEachMigrate(java.sql.Connection, org.flywaydb.core.api.MigrationInfo) */ @Override public void beforeEachMigrate(Connection connection, MigrationInfo info) { out.println("[Hibernate Service] Flyway migrate: " + info.getVersion().toString()); }
@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(); }
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(); } }
@Override public String getSchemaVersion() throws TopiaMigrationServiceException { MigrationInfo currentOrNull = flyway.info().current(); if (currentOrNull == null) { throw new TopiaMigrationServiceException("schema version is unknown"); } String schemaVersion = currentOrNull.getVersion().getVersion(); return schemaVersion; }
private void printFlywayInfo(MigrationInfo... infos){ MigrationInfo[] all = ArrayUtils.nullToEmpty(infos); if(all.length > 0){ for (MigrationInfo migrationInfo : all) { out.println("[Hibernate Service] Flyway Information:"); out.println("Version: " + migrationInfo.getVersion().toString()); out.println("Description: " + migrationInfo.getDescription()); out.println("Date: " + migrationInfo.getInstalledOn()); out.println("State: " + migrationInfo.getState().name()); out.println("Type: " + migrationInfo.getType().name()); out.println("[Hibernate Service] -------------------"); } } } }
@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; }
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; throw new ClassNotFoundException( String.format("Could not find an instance of %s which supports database " + "version %s.", VersionedDatabaseJobHistoryStore.class.getSimpleName(), requiredVersion.toString()));
private void startSchemaMigration() { final Flyway flyway = new Flyway(); flyway.setDataSource(jdbcConsumerHikariDataSource()); flyway.setLocations(properties.getFlywayScriptsLocation()); log.info("Starting Trafficsoft Delivery schema migration v{}", flyway.getBaselineVersion().getVersion()); flyway.migrate(); } }
@Override public void addAppliedMigration(final AppliedMigration appliedMigration) { final MigrationVersion version = appliedMigration.getVersion(); final String versionStr = version == null ? null : version.toString(); final int calculateInstalledRank; try {
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") ); } });
if (revision.equalsIgnoreCase(info.getVersion().getVersion())) { entity = info; break;
flyway.setBaselineVersion(MigrationVersion.fromVersion(flywayBaselineVersion)); flyway.setTarget(MigrationVersion.fromVersion(targetVersion)); } else {
appliedMigration.getVersionRank(), appliedMigration.getInstalledRank(), appliedMigration.getVersion().getVersion(), appliedMigration.getDescription(), appliedMigration.getType().name(),
@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; } }