mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-30 11:26:23 +00:00
MINOR - Simplify migration context computing during tests (#23097)
This commit is contained in:
parent
14e343c085
commit
1b39c9ca17
@ -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());
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
computeMigrationSafely(context);
|
||||
if (compute) {
|
||||
computeMigrationSafely(context);
|
||||
} else {
|
||||
this.migrationContext.put(context.getVersion(), context);
|
||||
}
|
||||
}
|
||||
|
||||
private void computeMigrationSafely(MigrationContext context) {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user