mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-30 19:36:41 +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 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());
|
||||||
|
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
@ -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() {
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user