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 static final String SUCCESS_MSG = "Success";
public static final String FAILED_MSG = "Failed due to : ";
public static final String CURRENT = "Current";
private List<MigrationProcess> migrations;
private final String nativeSQLScriptRootPath;
private final ConnectionType connectionType;
@ -249,7 +250,12 @@ public class MigrationWorkflow {
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 =
Arrays.asList(
"Version",
@ -261,12 +267,18 @@ public class MigrationWorkflow {
List<List<String>> allRows = new ArrayList<>();
try (Handle transactionHandler = jdbi.open()) {
MigrationWorkflowContext context = new MigrationWorkflowContext(transactionHandler);
if (currentMaxMigrationVersion.isPresent()) {
LOG.debug("Current Max version {}", currentMaxMigrationVersion.get());
context.computeInitialContext(currentMaxMigrationVersion.get());
} else {
context.computeInitialContext("1.1.0");
}
String currentVersion = currentMaxMigrationVersion.orElse(CURRENT);
LOG.debug("Current Max version {}", currentVersion);
// Add the current version context
context.computeInitialContext(currentVersion);
allRows.add(
List.of(
currentVersion,
CURRENT,
CURRENT,
CURRENT,
CURRENT,
context.getMigrationContext().get(currentVersion).getResults().toString()));
LOG.info("[MigrationWorkflow] WorkFlow Started");
try {
for (MigrationProcess process : migrations) {
@ -291,8 +303,9 @@ public class MigrationWorkflow {
// Post DDL Scripts
runPostDDLChanges(row, process);
// Build Context
context.computeMigrationContext(process);
// Build Context only if required (during ops), or if it's the last migration
context.computeMigrationContext(
process, computeAllContext || migrations.indexOf(process) == migrations.size() - 1);
row.add(
context.getMigrationContext().get(process.getVersion()).getResults().toString());

View File

@ -25,7 +25,7 @@ public class MigrationOps {
try {
this.result = handle.createQuery(query).mapTo(Long.class).one();
} 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));
}
public void computeMigrationContext(MigrationProcess process) {
public void computeMigrationContext(MigrationProcess process, boolean compute) {
MigrationContext context =
new MigrationContext(process.getVersion(), process.getMigrationOps(), handle);
if (compute) {
computeMigrationSafely(context);
} else {
this.migrationContext.put(context.getVersion(), context);
}
}
private void computeMigrationSafely(MigrationContext context) {

View File

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

View File

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