FINERACT-1724: Upgrade liquibase and set proper liquibase logging
This commit is contained in:
@@ -199,7 +199,7 @@ dependencyManagement {
|
|||||||
exclude 'jakarta.activation:jakarta.activation-api'
|
exclude 'jakarta.activation:jakarta.activation-api'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency ('org.liquibase:liquibase-core:4.19.0') {
|
dependency ('org.liquibase:liquibase-core:4.21.1') {
|
||||||
exclude 'javax.xml.bind:jaxb-api'
|
exclude 'javax.xml.bind:jaxb-api'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-15
@@ -89,7 +89,7 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeTenantStore() throws LiquibaseException {
|
private void upgradeTenantStore() throws LiquibaseException {
|
||||||
log.warn("Upgrading tenant store DB at {}:{}", fineractProperties.getTenant().getHost(), fineractProperties.getTenant().getPort());
|
log.info("Upgrading tenant store DB at {}:{}", fineractProperties.getTenant().getHost(), fineractProperties.getTenant().getPort());
|
||||||
logTenantStoreDetails();
|
logTenantStoreDetails();
|
||||||
if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
|
if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
|
||||||
ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_STORE_DB_CONTEXT, INITIAL_SWITCH_CONTEXT);
|
ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_STORE_DB_CONTEXT, INITIAL_SWITCH_CONTEXT);
|
||||||
@@ -98,7 +98,7 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
|||||||
}
|
}
|
||||||
SpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_STORE_DB_CONTEXT);
|
SpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_STORE_DB_CONTEXT);
|
||||||
liquibase.afterPropertiesSet();
|
liquibase.afterPropertiesSet();
|
||||||
log.warn("Tenant store upgrade finished");
|
log.info("Tenant store upgrade finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logTenantStoreDetails() {
|
private void logTenantStoreDetails() {
|
||||||
@@ -110,36 +110,47 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
|||||||
log.info("- fineract.tenant.identifier: {}", fineractProperties.getTenant().getIdentifier());
|
log.info("- fineract.tenant.identifier: {}", fineractProperties.getTenant().getIdentifier());
|
||||||
log.info("- fineract.tenant.name: {}", fineractProperties.getTenant().getName());
|
log.info("- fineract.tenant.name: {}", fineractProperties.getTenant().getName());
|
||||||
|
|
||||||
log.info("- fineract.tenant.username: {}", fineractProperties.getTenant().getReadOnlyUsername());
|
log.info("- fineract.tenant.readonly.username: {}", fineractProperties.getTenant().getReadOnlyUsername());
|
||||||
log.info("- fineract.tenant.password: {}",
|
log.info("- fineract.tenant.readonly.password: {}",
|
||||||
StringUtils.isNotBlank(fineractProperties.getTenant().getReadOnlyPassword()) ? "****" : "");
|
StringUtils.isNotBlank(fineractProperties.getTenant().getReadOnlyPassword()) ? "****" : "");
|
||||||
log.info("- fineract.tenant.parameters: {}", fineractProperties.getTenant().getReadOnlyParameters());
|
log.info("- fineract.tenant.readonly.parameters: {}", fineractProperties.getTenant().getReadOnlyParameters());
|
||||||
log.info("- fineract.tenant.name: {}", fineractProperties.getTenant().getReadOnlyName());
|
log.info("- fineract.tenant.readonly.name: {}", fineractProperties.getTenant().getReadOnlyName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeIndividualTenants() throws LiquibaseException {
|
private void upgradeIndividualTenants() throws LiquibaseException {
|
||||||
log.warn("Upgrading all tenants");
|
log.info("Upgrading all tenants");
|
||||||
List<FineractPlatformTenant> tenants = tenantDetailsService.findAllTenants();
|
List<FineractPlatformTenant> tenants = tenantDetailsService.findAllTenants();
|
||||||
if (isNotEmpty(tenants)) {
|
if (isNotEmpty(tenants)) {
|
||||||
for (FineractPlatformTenant tenant : tenants) {
|
for (FineractPlatformTenant tenant : tenants) {
|
||||||
upgradeIndividualTenant(tenant);
|
upgradeIndividualTenant(tenant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.warn("Tenant upgrades have finished");
|
log.info("Tenant upgrades have finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade each tenant's database
|
||||||
|
*
|
||||||
|
* Good to know: Each tenant's identifier is provided as a context variable to avoid caching of the liquibase
|
||||||
|
* migration (it was introduced as part of v4.21.0)
|
||||||
|
*
|
||||||
|
* @param tenant
|
||||||
|
* @throws LiquibaseException
|
||||||
|
*/
|
||||||
private void upgradeIndividualTenant(FineractPlatformTenant tenant) throws LiquibaseException {
|
private void upgradeIndividualTenant(FineractPlatformTenant tenant) throws LiquibaseException {
|
||||||
log.info("Upgrade for tenant {} has started", tenant.getTenantIdentifier());
|
log.info("Upgrade for tenant {} has started", tenant.getTenantIdentifier());
|
||||||
DataSource tenantDataSource = tenantDataSourceFactory.create(tenant);
|
DataSource tenantDataSource = tenantDataSourceFactory.create(tenant);
|
||||||
if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
|
if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) {
|
||||||
ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, INITIAL_SWITCH_CONTEXT);
|
ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, INITIAL_SWITCH_CONTEXT,
|
||||||
|
tenant.getTenantIdentifier());
|
||||||
applyInitialLiquibase(tenantDataSource, liquibase, tenant.getTenantIdentifier(),
|
applyInitialLiquibase(tenantDataSource, liquibase, tenant.getTenantIdentifier(),
|
||||||
(ds) -> !databaseStateVerifier.isTenantOnLatestUpgradableVersion(ds));
|
(ds) -> !databaseStateVerifier.isTenantOnLatestUpgradableVersion(ds));
|
||||||
}
|
}
|
||||||
SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT);
|
SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, tenant.getTenantIdentifier());
|
||||||
tenantLiquibase.afterPropertiesSet();
|
tenantLiquibase.afterPropertiesSet();
|
||||||
SpringLiquibase customChangelogLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT);
|
SpringLiquibase customChangelogLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT,
|
||||||
|
tenant.getTenantIdentifier());
|
||||||
customChangelogLiquibase.afterPropertiesSet();
|
customChangelogLiquibase.afterPropertiesSet();
|
||||||
log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier());
|
log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier());
|
||||||
}
|
}
|
||||||
@@ -148,13 +159,13 @@ public class TenantDatabaseUpgradeService implements InitializingBean {
|
|||||||
Function<DataSource, Boolean> isUpgradableFn) throws LiquibaseException {
|
Function<DataSource, Boolean> isUpgradableFn) throws LiquibaseException {
|
||||||
if (databaseStateVerifier.isFlywayPresent(dataSource)) {
|
if (databaseStateVerifier.isFlywayPresent(dataSource)) {
|
||||||
if (isUpgradableFn.apply(dataSource)) {
|
if (isUpgradableFn.apply(dataSource)) {
|
||||||
log.warn("Cannot proceed with upgrading database {}", id);
|
log.error("Cannot proceed with upgrading database {}", id);
|
||||||
log.warn("It seems the database doesn't have the latest schema changes applied until the 1.6 release");
|
log.error("It seems the database doesn't have the latest schema changes applied until the 1.6 release");
|
||||||
throw new SchemaUpgradeNeededException("Make sure to upgrade to Fineract 1.6 first and then to a newer version");
|
throw new SchemaUpgradeNeededException("Make sure to upgrade to Fineract 1.6 first and then to a newer version");
|
||||||
}
|
}
|
||||||
log.warn("This is the first Liquibase migration for {}. We'll sync the changelog for you and then apply everything else", id);
|
log.info("This is the first Liquibase migration for {}. We'll sync the changelog for you and then apply everything else", id);
|
||||||
liquibase.changeLogSync();
|
liquibase.changeLogSync();
|
||||||
log.warn("Liquibase changelog sync is complete");
|
log.info("Liquibase changelog sync is complete");
|
||||||
} else {
|
} else {
|
||||||
liquibase.afterPropertiesSet();
|
liquibase.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<logger name="org.springframework.boot.web.embedded.tomcat.TomcatWebServer" level="info"/>
|
<logger name="org.springframework.boot.web.embedded.tomcat.TomcatWebServer" level="info"/>
|
||||||
<logger name="org.apache.fineract.ServerApplication" level="info"/>
|
<logger name="org.apache.fineract.ServerApplication" level="info"/>
|
||||||
<logger name="org.apache.fineract" level="${FINERACT_LOGGING_LEVEL:-INFO}"/>
|
<logger name="org.apache.fineract" level="${FINERACT_LOGGING_LEVEL:-INFO}"/>
|
||||||
<logger name="liquibase" level="info"/>
|
<logger name="liquibase" level="warn"/>
|
||||||
|
|
||||||
<if condition="${jsonLoggingEnabled} == true">
|
<if condition="${jsonLoggingEnabled} == true">
|
||||||
<then>
|
<then>
|
||||||
|
|||||||
+6
-6
@@ -34,7 +34,6 @@ import java.util.List;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
import org.apache.fineract.infrastructure.core.service.database.DatabasePasswordEncryptor;
|
|
||||||
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibase;
|
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibase;
|
||||||
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibaseFactory;
|
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibaseFactory;
|
||||||
import org.apache.fineract.infrastructure.core.service.migration.SchemaUpgradeNeededException;
|
import org.apache.fineract.infrastructure.core.service.migration.SchemaUpgradeNeededException;
|
||||||
@@ -68,8 +67,6 @@ public class LiquibaseStepDefinitions implements En {
|
|||||||
private DataSource defaultTenantDataSource;
|
private DataSource defaultTenantDataSource;
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
private DatabasePasswordEncryptor databasePasswordEncryptor;
|
|
||||||
|
|
||||||
public LiquibaseStepDefinitions() {
|
public LiquibaseStepDefinitions() {
|
||||||
Given("Liquibase is disabled with a default tenant", () -> {
|
Given("Liquibase is disabled with a default tenant", () -> {
|
||||||
initializeLiquibase(false);
|
initializeLiquibase(false);
|
||||||
@@ -161,6 +158,7 @@ public class LiquibaseStepDefinitions implements En {
|
|||||||
liquibaseFactory = mock(ExtendedSpringLiquibaseFactory.class);
|
liquibaseFactory = mock(ExtendedSpringLiquibaseFactory.class);
|
||||||
|
|
||||||
defaultTenant = mock(FineractPlatformTenant.class);
|
defaultTenant = mock(FineractPlatformTenant.class);
|
||||||
|
given(defaultTenant.getTenantIdentifier()).willReturn("defaultTenant");
|
||||||
|
|
||||||
allTenants = List.of(defaultTenant);
|
allTenants = List.of(defaultTenant);
|
||||||
|
|
||||||
@@ -182,9 +180,11 @@ public class LiquibaseStepDefinitions implements En {
|
|||||||
|
|
||||||
given(tenantDetailsService.findAllTenants()).willReturn(allTenants);
|
given(tenantDetailsService.findAllTenants()).willReturn(allTenants);
|
||||||
given(tenantDataSourceFactory.create(defaultTenant)).willReturn(defaultTenantDataSource);
|
given(tenantDataSourceFactory.create(defaultTenant)).willReturn(defaultTenantDataSource);
|
||||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "initial_switch")).willReturn(initialTenantLiquibase);
|
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "initial_switch", "defaultTenant"))
|
||||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db")).willReturn(tenantLiquibase);
|
.willReturn(initialTenantLiquibase);
|
||||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "custom_changelog")).willReturn(customChangeLogLiquibase);
|
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "defaultTenant")).willReturn(tenantLiquibase);
|
||||||
|
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "custom_changelog", "defaultTenant"))
|
||||||
|
.willReturn(customChangeLogLiquibase);
|
||||||
|
|
||||||
tenantDatabaseUpgradeService = new TenantDatabaseUpgradeService(tenantDetailsService, tenantStoreDataSource, fineractProperties,
|
tenantDatabaseUpgradeService = new TenantDatabaseUpgradeService(tenantDetailsService, tenantStoreDataSource, fineractProperties,
|
||||||
databaseStateVerifier, liquibaseFactory, tenantDataSourceFactory, environment, Arrays.asList(tenantPasswordEncryptor));
|
databaseStateVerifier, liquibaseFactory, tenantDataSourceFactory, environment, Arrays.asList(tenantPasswordEncryptor));
|
||||||
|
|||||||
@@ -102,10 +102,6 @@
|
|||||||
"matchPackageNames": ["com.diffplug.spotless"],
|
"matchPackageNames": ["com.diffplug.spotless"],
|
||||||
"allowedVersions": "<=6.15.0"
|
"allowedVersions": "<=6.15.0"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"matchPackageNames": ["org.liquibase:liquibase-core"],
|
|
||||||
"allowedVersions": "<=4.19.0"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"depTypeList": ["dependencies"],
|
"depTypeList": ["dependencies"],
|
||||||
"updateTypes": ["patch", "minor"],
|
"updateTypes": ["patch", "minor"],
|
||||||
|
|||||||
Reference in New Issue
Block a user