From d9ff027480d0660035c4523f248940c10c086afd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 12 Sep 2024 11:53:43 +0200 Subject: [PATCH] Add FlowableVersionState to make it possible to provide all the next versions that should be upgraded instead of using a simple incrementing integer --- .../app/engine/impl/db/AppDbSchemaManager.java | 7 +++++++ .../cmmn/engine/impl/db/CmmnDbSchemaManager.java | 7 +++++++ .../dmn/engine/impl/db/DmnDbSchemaManager.java | 7 +++++++ .../common/engine/impl/FlowableVersion.java | 2 ++ .../common/engine/impl/FlowableVersions.java | 7 +++++++ .../db/AbstractSqlScriptBasedDbSchemaManager.java | 14 ++++++++++---- .../db/EngineSqlScriptBasedDbSchemaManager.java | 15 ++++++++------- .../impl/db/EventDbSchemaManager.java | 7 +++++++ 8 files changed, 55 insertions(+), 11 deletions(-) diff --git a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/db/AppDbSchemaManager.java b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/db/AppDbSchemaManager.java index 1af893bc553..5bdcf5c3c2f 100644 --- a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/db/AppDbSchemaManager.java +++ b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/db/AppDbSchemaManager.java @@ -17,6 +17,8 @@ import org.apache.commons.lang3.StringUtils; import org.flowable.app.engine.AppEngine; import org.flowable.app.engine.impl.util.CommandContextUtil; +import org.flowable.common.engine.impl.FlowableVersion; +import org.flowable.common.engine.impl.FlowableVersions; import org.flowable.common.engine.impl.db.EngineSchemaManagerLockConfiguration; import org.flowable.common.engine.impl.db.EngineSqlScriptBasedDbSchemaManager; @@ -67,6 +69,11 @@ protected String getDbVersionForChangelogVersion(String changeLogVersion) { return "6.3.0.1"; } + @Override + protected FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion) { + return FlowableVersions.getVersionStateForDbVersion(dbVersion); + } + @Override protected String getResourcesRootDirectory() { return "org/flowable/app/db/"; diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/db/CmmnDbSchemaManager.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/db/CmmnDbSchemaManager.java index 6acdb3b1f8b..7b4ed25d78b 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/db/CmmnDbSchemaManager.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/db/CmmnDbSchemaManager.java @@ -17,6 +17,8 @@ import org.apache.commons.lang3.StringUtils; import org.flowable.cmmn.engine.CmmnEngine; import org.flowable.cmmn.engine.impl.util.CommandContextUtil; +import org.flowable.common.engine.impl.FlowableVersion; +import org.flowable.common.engine.impl.FlowableVersions; import org.flowable.common.engine.impl.db.EngineSchemaManagerLockConfiguration; import org.flowable.common.engine.impl.db.EngineSqlScriptBasedDbSchemaManager; @@ -84,6 +86,11 @@ protected String getDbVersionForChangelogVersion(String changeLogVersion) { return "6.1.2.0"; } + @Override + protected FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion) { + return FlowableVersions.getVersionStateForDbVersion(dbVersion); + } + @Override protected String getResourcesRootDirectory() { return "org/flowable/cmmn/db/"; diff --git a/modules/flowable-dmn-engine/src/main/java/org/flowable/dmn/engine/impl/db/DmnDbSchemaManager.java b/modules/flowable-dmn-engine/src/main/java/org/flowable/dmn/engine/impl/db/DmnDbSchemaManager.java index e3ce6d89f65..4a436bcc581 100644 --- a/modules/flowable-dmn-engine/src/main/java/org/flowable/dmn/engine/impl/db/DmnDbSchemaManager.java +++ b/modules/flowable-dmn-engine/src/main/java/org/flowable/dmn/engine/impl/db/DmnDbSchemaManager.java @@ -16,6 +16,8 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.impl.FlowableVersion; +import org.flowable.common.engine.impl.FlowableVersions; import org.flowable.common.engine.impl.db.EngineSchemaManagerLockConfiguration; import org.flowable.common.engine.impl.db.EngineSqlScriptBasedDbSchemaManager; import org.flowable.dmn.engine.DmnEngine; @@ -75,6 +77,11 @@ protected String getDbVersionForChangelogVersion(String changeLogVersion) { return "5.99.0.0"; } + @Override + protected FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion) { + return FlowableVersions.getVersionStateForDbVersion(dbVersion); + } + @Override protected String getResourcesRootDirectory() { return "org/flowable/dmn/db/"; diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersion.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersion.java index 16a597baf5f..1da21cc4c0b 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersion.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersion.java @@ -79,4 +79,6 @@ public boolean equals(Object obj) { } } + public record VersionState(FlowableVersion currentVersion, List nextVersions) { + } } diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersions.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersions.java index d09690de2d0..a3be8a92f6e 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersions.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/FlowableVersions.java @@ -201,6 +201,13 @@ public static int getFlowableVersionIndexForDbVersion(String dbVersion) { return matchingVersionIndex; } + public static FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion) { + int dbVersionIndex = FlowableVersions.getFlowableVersionIndexForDbVersion(dbVersion); + FlowableVersion currentVersion = FlowableVersions.FLOWABLE_VERSIONS.get(dbVersionIndex); + + return new FlowableVersion.VersionState(currentVersion, FlowableVersions.FLOWABLE_VERSIONS.subList(dbVersionIndex + 1, FlowableVersions.FLOWABLE_VERSIONS.size())); + } + public static boolean hasCamMigrationVersion(String version) { int index = findMatchingCamMigrationIndex(version); if (index >= 0) { diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java index 59e5d7021f6..5236f0735db 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/AbstractSqlScriptBasedDbSchemaManager.java @@ -23,6 +23,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.List; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.impl.FlowableVersion; @@ -83,12 +84,17 @@ protected void dbSchemaUpgradeUntil6120(final String component, final int curren protected void dbSchemaUpgrade(final String component, final int currentDatabaseVersionsIndex, final String engineDbVersion) { FlowableVersion version = FlowableVersions.FLOWABLE_VERSIONS.get(currentDatabaseVersionsIndex); - String currentVersion = version.getMainVersion(); - logger.info("upgrading flowable {} schema from {} to {}", component, currentVersion, FlowableVersions.CURRENT_VERSION); + dbSchemaUpgrade(component, new FlowableVersion.VersionState(version, FlowableVersions.FLOWABLE_VERSIONS.subList(currentDatabaseVersionsIndex + 1, FlowableVersions.FLOWABLE_VERSIONS.size())), engineDbVersion); + } + + protected void dbSchemaUpgrade(String component, FlowableVersion.VersionState versionState, String engineDbVersion) { + String currentVersion = versionState.currentVersion().getMainVersion(); + List nextVersions = versionState.nextVersions(); + logger.info("upgrading flowable {} schema from {} to {}", component, currentVersion, nextVersions.get(nextVersions.size() - 1).getMainVersion()); // Actual execution of schema DDL SQL - for (int i = currentDatabaseVersionsIndex + 1; i < FlowableVersions.FLOWABLE_VERSIONS.size(); i++) { - String nextVersion = FlowableVersions.FLOWABLE_VERSIONS.get(i).getMainVersion(); + for (FlowableVersion version : nextVersions) { + String nextVersion = version.getMainVersion(); // Taking care of -SNAPSHOT version in development if (nextVersion.endsWith("-SNAPSHOT")) { diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/EngineSqlScriptBasedDbSchemaManager.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/EngineSqlScriptBasedDbSchemaManager.java index a901834b40b..373a4b54e19 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/EngineSqlScriptBasedDbSchemaManager.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/EngineSqlScriptBasedDbSchemaManager.java @@ -19,7 +19,7 @@ import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.FlowableWrongDbException; import org.flowable.common.engine.api.lock.LockManager; -import org.flowable.common.engine.impl.FlowableVersions; +import org.flowable.common.engine.impl.FlowableVersion; public abstract class EngineSqlScriptBasedDbSchemaManager extends AbstractSqlScriptBasedDbSchemaManager { @@ -43,6 +43,8 @@ protected EngineSqlScriptBasedDbSchemaManager(String context, SchemaManagerLockC protected abstract String getDbVersionForChangelogVersion(String changeLogVersion); + protected abstract FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion); + @Override public void schemaCheckVersion() { try { @@ -132,8 +134,6 @@ public String schemaUpdate() { protected String schemaUpdateInLock() { String feedback = null; - boolean isUpgradeNeeded = false; - int matchingVersionIndex = -1; boolean isEngineTablePresent = isEngineTablePresent(); @@ -147,14 +147,15 @@ protected String schemaUpdateInLock() { } } + FlowableVersion.VersionState versionState = null; + if (isEngineTablePresent) { - matchingVersionIndex = FlowableVersions.getFlowableVersionIndexForDbVersion(dbVersion); - isUpgradeNeeded = (matchingVersionIndex != (FlowableVersions.FLOWABLE_VERSIONS.size() - 1)); + versionState = getVersionStateForDbVersion(dbVersion); } - if (isUpgradeNeeded) { + if (versionState != null && !versionState.nextVersions().isEmpty()) { // Engine upgrade - dbSchemaUpgrade(context, matchingVersionIndex, dbVersion); + dbSchemaUpgrade(context, versionState, dbVersion); dbSchemaUpgraded(changeLogVersion); feedback = "upgraded Flowable from " + dbVersion + " to " + getEngineVersion(); diff --git a/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/db/EventDbSchemaManager.java b/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/db/EventDbSchemaManager.java index b4558f6977f..2fa67f7f60a 100644 --- a/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/db/EventDbSchemaManager.java +++ b/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/db/EventDbSchemaManager.java @@ -16,6 +16,8 @@ import org.apache.commons.lang3.StringUtils; import org.flowable.common.engine.impl.AbstractEngineConfiguration; +import org.flowable.common.engine.impl.FlowableVersion; +import org.flowable.common.engine.impl.FlowableVersions; import org.flowable.common.engine.impl.db.EngineSchemaManagerLockConfiguration; import org.flowable.common.engine.impl.db.EngineSqlScriptBasedDbSchemaManager; import org.flowable.eventregistry.impl.EventRegistryEngine; @@ -71,6 +73,11 @@ protected String getDbVersionForChangelogVersion(String changeLogVersion) { return "6.5.0.0"; } + @Override + protected FlowableVersion.VersionState getVersionStateForDbVersion(String dbVersion) { + return FlowableVersions.getVersionStateForDbVersion(dbVersion); + } + protected AbstractEngineConfiguration getEngineConfiguration() { return CommandContextUtil.getEventRegistryConfiguration(); }