Skip to content

Commit

Permalink
FINERACT-2119: Address jobs by name - fix liquibase order for custom …
Browse files Browse the repository at this point in the history
…modules
  • Loading branch information
Marta Jankovics authored and vidakovic committed Sep 1, 2024
1 parent 8b89aaf commit d5d7f7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand Down

0 comments on commit d5d7f7f

Please sign in to comment.