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());