From d5d7f7f5a0257914d87c5cc50361c1dbd5beb57f Mon Sep 17 00:00:00 2001 From: Marta Jankovics Date: Fri, 30 Aug 2024 17:30:05 +0200 Subject: [PATCH] FINERACT-2119: Address jobs by name - fix liquibase order for custom modules --- .../TenantDatabaseUpgradeService.java | 20 ++++++++--------- .../core/LiquibaseStepDefinitions.java | 22 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java index c65b6b10175..75a1f8dafbf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/migration/TenantDatabaseUpgradeService.java @@ -47,10 +47,10 @@ @RequiredArgsConstructor public class TenantDatabaseUpgradeService implements InitializingBean { - private static final String TENANT_STORE_DB_CONTEXT = "tenant_store_db"; - private static final String INITIAL_SWITCH_CONTEXT = "initial_switch"; - private static final String TENANT_DB_CONTEXT = "tenant_db"; - private static final String CUSTOM_CHANGELOG_CONTEXT = "custom_changelog"; + public static final String TENANT_STORE_DB_CONTEXT = "tenant_store_db"; + public static final String INITIAL_SWITCH_CONTEXT = "initial_switch"; + public static final String TENANT_DB_CONTEXT = "tenant_db"; + public static final String CUSTOM_CHANGELOG_CONTEXT = "custom_changelog"; private final TenantDetailsService tenantDetailsService; @Qualifier("hikariTenantDataSource") @@ -144,17 +144,17 @@ private void upgradeIndividualTenants() throws LiquibaseException { private void upgradeIndividualTenant(FineractPlatformTenant tenant) throws LiquibaseException { log.info("Upgrade for tenant {} has started", tenant.getTenantIdentifier()); DataSource tenantDataSource = tenantDataSourceFactory.create(tenant); + // 'initial_switch' and 'custom_changelog' contexts should be controlled by the application configuration + // settings, and we should not use them to control the script order if (databaseStateVerifier.isFirstLiquibaseMigration(tenantDataSource)) { - ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, INITIAL_SWITCH_CONTEXT, - tenant.getTenantIdentifier()); + ExtendedSpringLiquibase liquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT, + INITIAL_SWITCH_CONTEXT, tenant.getTenantIdentifier()); applyInitialLiquibase(tenantDataSource, liquibase, tenant.getTenantIdentifier(), (ds) -> !databaseStateVerifier.isTenantOnLatestUpgradableVersion(ds)); } - SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, tenant.getTenantIdentifier()); - tenantLiquibase.afterPropertiesSet(); - SpringLiquibase customChangelogLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT, + SpringLiquibase tenantLiquibase = liquibaseFactory.create(tenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT, tenant.getTenantIdentifier()); - customChangelogLiquibase.afterPropertiesSet(); + tenantLiquibase.afterPropertiesSet(); log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier()); } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/core/LiquibaseStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/core/LiquibaseStepDefinitions.java index bec504a26d5..e706a90044c 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/core/LiquibaseStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/core/LiquibaseStepDefinitions.java @@ -18,6 +18,10 @@ */ package org.apache.fineract.infrastructure.core; +import static org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseUpgradeService.CUSTOM_CHANGELOG_CONTEXT; +import static org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseUpgradeService.INITIAL_SWITCH_CONTEXT; +import static org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseUpgradeService.TENANT_DB_CONTEXT; +import static org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseUpgradeService.TENANT_STORE_DB_CONTEXT; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -57,7 +61,6 @@ public class LiquibaseStepDefinitions implements En { private ExtendedSpringLiquibase tenantStoreLiquibase; private ExtendedSpringLiquibase initialTenantLiquibase; private ExtendedSpringLiquibase tenantLiquibase; - private ExtendedSpringLiquibase customChangeLogLiquibase; private FineractPlatformTenant defaultTenant; private DataSource tenantStoreDataSource; private TenantDatabaseUpgradeService tenantDatabaseUpgradeService; @@ -127,7 +130,7 @@ public LiquibaseStepDefinitions() { assertThat(executionException).isNotNull(); verify(liquibaseFactory).create(eq(tenantStoreDataSource), anyString(), anyString()); verify(liquibaseFactory).create(eq(tenantStoreDataSource), anyString()); - verify(liquibaseFactory).create(eq(defaultTenantDataSource), anyString(), anyString(), anyString()); + verify(liquibaseFactory).create(eq(defaultTenantDataSource), anyString(), anyString(), anyString(), anyString()); verifyNoMoreInteractions(liquibaseFactory); verify(initialTenantStoreLiquibase).changeLogSync(); verify(tenantStoreLiquibase).afterPropertiesSet(); @@ -166,7 +169,6 @@ private void initializeLiquibase(boolean liquibaseEnabled) { initialTenantLiquibase = mock(ExtendedSpringLiquibase.class); tenantLiquibase = mock(ExtendedSpringLiquibase.class); - customChangeLogLiquibase = mock(ExtendedSpringLiquibase.class); initialTenantStoreLiquibase = mock(ExtendedSpringLiquibase.class); tenantStoreLiquibase = mock(ExtendedSpringLiquibase.class); @@ -175,16 +177,16 @@ private void initializeLiquibase(boolean liquibaseEnabled) { TenantPasswordEncryptionTask tenantPasswordEncryptor = mock(TenantPasswordEncryptionTask.class); given(databaseStateVerifier.isLiquibaseDisabled()).willReturn(!liquibaseEnabled); - given(liquibaseFactory.create(tenantStoreDataSource, "tenant_store_db", "initial_switch")).willReturn(initialTenantStoreLiquibase); - given(liquibaseFactory.create(tenantStoreDataSource, "tenant_store_db")).willReturn(tenantStoreLiquibase); + given(liquibaseFactory.create(tenantStoreDataSource, TENANT_STORE_DB_CONTEXT, INITIAL_SWITCH_CONTEXT)) + .willReturn(initialTenantStoreLiquibase); + given(liquibaseFactory.create(tenantStoreDataSource, TENANT_STORE_DB_CONTEXT)).willReturn(tenantStoreLiquibase); given(tenantDetailsService.findAllTenants()).willReturn(allTenants); given(tenantDataSourceFactory.create(defaultTenant)).willReturn(defaultTenantDataSource); - given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "initial_switch", "defaultTenant")) - .willReturn(initialTenantLiquibase); - given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "defaultTenant")).willReturn(tenantLiquibase); - given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "custom_changelog", "defaultTenant")) - .willReturn(customChangeLogLiquibase); + given(liquibaseFactory.create(defaultTenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT, INITIAL_SWITCH_CONTEXT, + "defaultTenant")).willReturn(initialTenantLiquibase); + given(liquibaseFactory.create(defaultTenantDataSource, TENANT_DB_CONTEXT, CUSTOM_CHANGELOG_CONTEXT, "defaultTenant")) + .willReturn(tenantLiquibase); tenantDatabaseUpgradeService = new TenantDatabaseUpgradeService(tenantDetailsService, tenantStoreDataSource, fineractProperties, databaseStateVerifier, liquibaseFactory, tenantDataSourceFactory, environment, Arrays.asList(tenantPasswordEncryptor));