use of org.flywaydb.core.api.FlywayException in project dhis2-core by dhis2.
the class V2_34_6__Convert_systemsetting_value_column_from_bytea_to_string method fillNewColWithTransformedData.
private void fillNewColWithTransformedData(final Context context, Set<SystemSetting> systemSettingsToConvert) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper specialObjectMapper = new ObjectMapper();
specialObjectMapper.setVisibility(specialObjectMapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(Visibility.ANY).withGetterVisibility(Visibility.NONE).withSetterVisibility(Visibility.NONE).withCreatorVisibility(Visibility.NONE));
try (PreparedStatement ps = context.getConnection().prepareStatement("UPDATE systemsetting SET value_text = ? WHERE systemsettingid = ?")) {
for (SystemSetting systemSetting : systemSettingsToConvert) {
if (systemSetting.getName().equals(SMS_CONFIGURATION_SETTING_NAME)) {
ps.setString(1, specialObjectMapper.writeValueAsString(systemSetting.getValue()));
} else {
ps.setString(1, objectMapper.writeValueAsString(systemSetting.getValue()));
}
ps.setLong(2, systemSetting.getId());
ps.execute();
}
} catch (SQLException e) {
log.error("Flyway java migration error:", e);
throw new FlywayException(e);
}
}
use of org.flywaydb.core.api.FlywayException in project killbill by killbill.
the class DbMigrateWithDryRun method applyMigration.
private void applyMigration(final int installedRnk, final MigrationInfoImpl migration) {
final MigrationVersion version = migration.getVersion();
final String migrationText;
if (version != null) {
migrationText = "schema " + schema + " to version " + version + " - " + migration.getDescription();
} else {
migrationText = "schema " + schema + " with repeatable migration " + migration.getDescription();
}
LOG.info("Migrating " + migrationText);
// PIERRE: override the executor to capture the SQL
final FileSystemResource sqlScriptResource = new FileSystemResource(migration.getResolvedMigration().getPhysicalLocation());
final MigrationExecutor migrationExecutor = new CapturingSqlMigrationExecutor(sqlStatements, dbSupport, sqlScriptResource, placeholderReplacer, encoding);
try {
doMigrate(migration, migrationExecutor, migrationText);
} catch (final SQLException e) {
throw new FlywayException("Unable to apply migration", e);
}
final AppliedMigration appliedMigration = new AppliedMigration(installedRnk, version, migration.getDescription(), migration.getType(), migration.getScript(), migration.getResolvedMigration().getChecksum(), null, null, -1, true);
metaDataTableForDryRun.addAppliedMigration(appliedMigration);
}
Aggregations