forked from Onlineberatung/onlineBeratung-migrationTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Onlineberatung:develop' into develop
- Loading branch information
Showing
6 changed files
with
132 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/vi/migrationtool/tenantservice/EnableTenantLevelToggleMigrationTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.vi.migrationtool.tenantservice; | ||
|
||
import com.vi.migrationtool.common.MigrationTasks; | ||
import com.vi.migrationtool.config.BeanAwareSpringLiquibase; | ||
import liquibase.database.Database; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jsoup.helper.Validate; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@Slf4j | ||
@Setter | ||
public class EnableTenantLevelToggleMigrationTask extends MigrationTasks { | ||
|
||
String featureToggleName; | ||
|
||
@Override | ||
public void execute(Database database) { | ||
Validate.notNull(featureToggleName, "Feature toggle name must not be null"); | ||
var tenantServiceJdbcTemplate = | ||
BeanAwareSpringLiquibase.getNamedBean("tenantServiceJdbcTemplate", JdbcTemplate.class); | ||
log.info("Activating tenant level toggle" + featureToggleName + " for all tenants"); | ||
activateFeatureToggle(tenantServiceJdbcTemplate); | ||
} | ||
|
||
private void activateFeatureToggle(JdbcTemplate tenantServiceJdbcTemplate) { | ||
int[] updatedTenants = | ||
tenantServiceJdbcTemplate.batchUpdate( | ||
"update tenant set settings = REPLACE( settings ,'\"" | ||
+ featureToggleName | ||
+ "\":false','\"" | ||
+ featureToggleName | ||
+ "\":true') where settings like '%" | ||
+ "\"" | ||
+ featureToggleName | ||
+ "\"" | ||
+ ":false%';"); | ||
|
||
log.info("Updated toggle value for {} tenants", updatedTenants[0]); | ||
|
||
int[] tenantsWithAddedSettings = | ||
tenantServiceJdbcTemplate.batchUpdate( | ||
"update tenant set settings = REPLACE(settings, '}',',\"" | ||
+ featureToggleName | ||
+ "\":true}')" | ||
+ " where settings not like '%" | ||
+ featureToggleName | ||
+ "%';"); | ||
|
||
log.info("Added feature toggle to {} tenants", tenantsWithAddedSettings[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...0027_enable_central_data_protection_toggle/0027_enable_central_data_protection_toggle.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd"> | ||
|
||
<changeSet author="tkuzynow" id="enable_central_data_protection_toggle"> | ||
<customChange class="com.vi.migrationtool.tenantservice.EnableTenantLevelToggleMigrationTask"> | ||
<param name="featureToggleName" value='featureCentralDataProtectionTemplateEnabled'/> | ||
</customChange> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters