MINOR - Simplify migration context computing during tests (#23097)

This commit is contained in:
Pere Miquel Brull 2025-08-27 08:35:55 +02:00 committed by GitHub
parent 14e343c085
commit 1b39c9ca17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 14 deletions

View File

@ -30,6 +30,7 @@ import org.openmetadata.service.util.AsciiTable;
public class MigrationWorkflow { public class MigrationWorkflow {
public static final String SUCCESS_MSG = "Success"; public static final String SUCCESS_MSG = "Success";
public static final String FAILED_MSG = "Failed due to : "; public static final String FAILED_MSG = "Failed due to : ";
public static final String CURRENT = "Current";
private List<MigrationProcess> migrations; private List<MigrationProcess> migrations;
private final String nativeSQLScriptRootPath; private final String nativeSQLScriptRootPath;
private final ConnectionType connectionType; private final ConnectionType connectionType;
@ -249,7 +250,12 @@ public class MigrationWorkflow {
printToAsciiTable(columns.stream().toList(), allRows, "No Server Migration To be Run"); printToAsciiTable(columns.stream().toList(), allRows, "No Server Migration To be Run");
} }
public void runMigrationWorkflows() { /**
* Run the Migration Workflow
* @param computeAllContext If true, compute the context for each executed migration. Otherwise, we'll only compute
* the context for the initial and last state of the database.
*/
public void runMigrationWorkflows(boolean computeAllContext) {
List<String> columns = List<String> columns =
Arrays.asList( Arrays.asList(
"Version", "Version",
@ -261,12 +267,18 @@ public class MigrationWorkflow {
List<List<String>> allRows = new ArrayList<>(); List<List<String>> allRows = new ArrayList<>();
try (Handle transactionHandler = jdbi.open()) { try (Handle transactionHandler = jdbi.open()) {
MigrationWorkflowContext context = new MigrationWorkflowContext(transactionHandler); MigrationWorkflowContext context = new MigrationWorkflowContext(transactionHandler);
if (currentMaxMigrationVersion.isPresent()) { String currentVersion = currentMaxMigrationVersion.orElse(CURRENT);
LOG.debug("Current Max version {}", currentMaxMigrationVersion.get()); LOG.debug("Current Max version {}", currentVersion);
context.computeInitialContext(currentMaxMigrationVersion.get()); // Add the current version context
} else { context.computeInitialContext(currentVersion);
context.computeInitialContext("1.1.0"); allRows.add(
} List.of(
currentVersion,
CURRENT,
CURRENT,
CURRENT,
CURRENT,
context.getMigrationContext().get(currentVersion).getResults().toString()));
LOG.info("[MigrationWorkflow] WorkFlow Started"); LOG.info("[MigrationWorkflow] WorkFlow Started");
try { try {
for (MigrationProcess process : migrations) { for (MigrationProcess process : migrations) {
@ -291,8 +303,9 @@ public class MigrationWorkflow {
// Post DDL Scripts // Post DDL Scripts
runPostDDLChanges(row, process); runPostDDLChanges(row, process);
// Build Context // Build Context only if required (during ops), or if it's the last migration
context.computeMigrationContext(process); context.computeMigrationContext(
process, computeAllContext || migrations.indexOf(process) == migrations.size() - 1);
row.add( row.add(
context.getMigrationContext().get(process.getVersion()).getResults().toString()); context.getMigrationContext().get(process.getVersion()).getResults().toString());

View File

@ -25,7 +25,7 @@ public class MigrationOps {
try { try {
this.result = handle.createQuery(query).mapTo(Long.class).one(); this.result = handle.createQuery(query).mapTo(Long.class).one();
} catch (Exception ex) { } catch (Exception ex) {
LOG.warn(String.format("Migration Op [%s] failed due to [%s]", name, ex)); LOG.debug(String.format("Migration Op [%s] failed due to [%s]", name, ex));
} }
} }
} }

View File

@ -21,10 +21,14 @@ public class MigrationWorkflowContext {
computeMigrationSafely(new MigrationContext(currentMaxMigrationVersion, List.of(), handle)); computeMigrationSafely(new MigrationContext(currentMaxMigrationVersion, List.of(), handle));
} }
public void computeMigrationContext(MigrationProcess process) { public void computeMigrationContext(MigrationProcess process, boolean compute) {
MigrationContext context = MigrationContext context =
new MigrationContext(process.getVersion(), process.getMigrationOps(), handle); new MigrationContext(process.getVersion(), process.getMigrationOps(), handle);
computeMigrationSafely(context); if (compute) {
computeMigrationSafely(context);
} else {
this.migrationContext.put(context.getVersion(), context);
}
} }
private void computeMigrationSafely(MigrationContext context) { private void computeMigrationSafely(MigrationContext context) {

View File

@ -1576,7 +1576,7 @@ public class OpenMetadataOperations implements Callable<Integer> {
jdbi, nativeSQLScriptRootPath, connType, extensionSQLScriptRootPath, config, force); jdbi, nativeSQLScriptRootPath, connType, extensionSQLScriptRootPath, config, force);
workflow.loadMigrations(); workflow.loadMigrations();
workflow.printMigrationInfo(); workflow.printMigrationInfo();
workflow.runMigrationWorkflows(); workflow.runMigrationWorkflows(true);
} }
private void initOrganization() { private void initOrganization() {

View File

@ -282,7 +282,7 @@ public abstract class OpenMetadataApplicationTest {
Entity.setJobDAO(jdbi.onDemand(JobDAO.class)); Entity.setJobDAO(jdbi.onDemand(JobDAO.class));
Entity.initializeRepositories(config, jdbi); Entity.initializeRepositories(config, jdbi);
workflow.loadMigrations(); workflow.loadMigrations();
workflow.runMigrationWorkflows(); workflow.runMigrationWorkflows(false);
WorkflowHandler.initialize(config); WorkflowHandler.initialize(config);
SettingsCache.initialize(config); SettingsCache.initialize(config);
ApplicationHandler.initialize(config); ApplicationHandler.initialize(config);