Skip to content

Commit 0307e9b

Browse files
yihzhouYihong Zhou
andauthored
feat(flyway): Add a new format of CONFIG FILE name with a service identifier (#423)
* feat(flyway): Add a new format of CONFIG FILE name with a service identifier A service identifier is provided by each GMA MP so when Asset MG reusing DAOs from various GMA MPs, it should go through multiple flyway migrations related to different DAO services, rather than now be confused by the duplicate config file name due to the share db between GMAs. * Change actions/upload-artifact@v2 to actions/upload-artifact@v3 to avoid job setup issue of deprecated version of v2 --------- Co-authored-by: Yihong Zhou <[email protected]>
1 parent 4c91222 commit 0307e9b

16 files changed

+551
-12
lines changed

dao-api/src/main/java/com/linkedin/metadata/dao/SchemaEvolutionManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ class Config {
2727
String connectionUrl;
2828
String password;
2929
String username;
30+
String serviceIdentifier;
3031
}
3132
}

dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanLocalAccess.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class EbeanLocalAccess<URN extends Urn> implements IEbeanLocalAccess<URN>
6868
private static final int DEFAULT_PAGE_SIZE = 1000;
6969
private static final String ASPECT_JSON_PLACEHOLDER = "__PLACEHOLDER__";
7070
private static final String DEFAULT_ACTOR = "urn:li:principal:UNKNOWN";
71+
private static final String SERVICE_IDENTIFIER = "SERVICE_IDENTIFIER";
7172

7273
// key: table_name,
7374
// value: Set(column1, column2, column3 ...)
@@ -494,10 +495,14 @@ private String toJsonString(@Nonnull URN urn) {
494495

495496
@Nonnull
496497
private SchemaEvolutionManager createSchemaEvolutionManager(@Nonnull ServerConfig serverConfig) {
498+
String identifier = serverConfig.getDataSourceConfig().getCustomProperties() != null
499+
? serverConfig.getDataSourceConfig().getCustomProperties().getOrDefault(SERVICE_IDENTIFIER, null)
500+
: null;
497501
SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
498502
serverConfig.getDataSourceConfig().getUrl(),
499503
serverConfig.getDataSourceConfig().getPassword(),
500-
serverConfig.getDataSourceConfig().getUsername());
504+
serverConfig.getDataSourceConfig().getUsername(),
505+
identifier);
501506

502507
return new FlywaySchemaEvolutionManager(config);
503508
}

dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/FlywaySchemaEvolutionManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
import java.util.Properties;
66
import org.flywaydb.core.Flyway;
77

8+
89
public class FlywaySchemaEvolutionManager implements SchemaEvolutionManager {
910
private static final String EVOLUTION_SCRIPTS_LOCATION = "script_directory";
1011
private static final String VERSION_TABLE = "version_table";
1112
private static final String CONFIG_FILE_TEMPLATE = "%s.conf";
13+
private static final String CONFIG_FILE_TEMPLATE2 = "%s-%s.conf";
1214
private static final String DISABLE_CLEAN = "disable_clean";
1315
private final Flyway _flyway;
1416

1517
public FlywaySchemaEvolutionManager(Config config) {
1618
String databaseName = getDatabaseName(config);
17-
InputStream configFile = getClass().getClassLoader().getResourceAsStream(String.format(CONFIG_FILE_TEMPLATE, databaseName));
19+
String serviceIdentifier = config.getServiceIdentifier();
20+
String configFileName = serviceIdentifier == null
21+
? String.format(CONFIG_FILE_TEMPLATE, databaseName) : String.format(CONFIG_FILE_TEMPLATE2, serviceIdentifier, databaseName);
1822
Properties configProp = new Properties();
1923

20-
try {
24+
try (InputStream configFile = getClass().getClassLoader().getResourceAsStream(configFileName)) {
2125
configProp.load(configFile);
2226

2327
if (!configProp.containsKey(EVOLUTION_SCRIPTS_LOCATION) || !configProp.containsKey(VERSION_TABLE)) {
@@ -42,7 +46,7 @@ public FlywaySchemaEvolutionManager(Config config) {
4246

4347
@Override
4448
public void ensureSchemaUpToDate() {
45-
_flyway.migrate();
49+
_flyway.migrate();
4650
}
4751

4852
@Override

0 commit comments

Comments
 (0)