Skip to content

Commit

Permalink
feat(flyway): Add a new format of CONFIG FILE name with a service ide…
Browse files Browse the repository at this point in the history
…ntifier (#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]>
  • Loading branch information
yihzhou and Yihong Zhou authored Sep 13, 2024
1 parent 4c91222 commit 0307e9b
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class Config {
String connectionUrl;
String password;
String username;
String serviceIdentifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class EbeanLocalAccess<URN extends Urn> implements IEbeanLocalAccess<URN>
private static final int DEFAULT_PAGE_SIZE = 1000;
private static final String ASPECT_JSON_PLACEHOLDER = "__PLACEHOLDER__";
private static final String DEFAULT_ACTOR = "urn:li:principal:UNKNOWN";
private static final String SERVICE_IDENTIFIER = "SERVICE_IDENTIFIER";

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

@Nonnull
private SchemaEvolutionManager createSchemaEvolutionManager(@Nonnull ServerConfig serverConfig) {
String identifier = serverConfig.getDataSourceConfig().getCustomProperties() != null
? serverConfig.getDataSourceConfig().getCustomProperties().getOrDefault(SERVICE_IDENTIFIER, null)
: null;
SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
serverConfig.getDataSourceConfig().getUrl(),
serverConfig.getDataSourceConfig().getPassword(),
serverConfig.getDataSourceConfig().getUsername());
serverConfig.getDataSourceConfig().getUsername(),
identifier);

return new FlywaySchemaEvolutionManager(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
import java.util.Properties;
import org.flywaydb.core.Flyway;


public class FlywaySchemaEvolutionManager implements SchemaEvolutionManager {
private static final String EVOLUTION_SCRIPTS_LOCATION = "script_directory";
private static final String VERSION_TABLE = "version_table";
private static final String CONFIG_FILE_TEMPLATE = "%s.conf";
private static final String CONFIG_FILE_TEMPLATE2 = "%s-%s.conf";
private static final String DISABLE_CLEAN = "disable_clean";
private final Flyway _flyway;

public FlywaySchemaEvolutionManager(Config config) {
String databaseName = getDatabaseName(config);
InputStream configFile = getClass().getClassLoader().getResourceAsStream(String.format(CONFIG_FILE_TEMPLATE, databaseName));
String serviceIdentifier = config.getServiceIdentifier();
String configFileName = serviceIdentifier == null
? String.format(CONFIG_FILE_TEMPLATE, databaseName) : String.format(CONFIG_FILE_TEMPLATE2, serviceIdentifier, databaseName);
Properties configProp = new Properties();

try {
try (InputStream configFile = getClass().getClassLoader().getResourceAsStream(configFileName)) {
configProp.load(configFile);

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

@Override
public void ensureSchemaUpToDate() {
_flyway.migrate();
_flyway.migrate();
}

@Override
Expand Down
Loading

0 comments on commit 0307e9b

Please sign in to comment.