Skip to content

Commit

Permalink
Add FlowableVersionState to make it possible to provide all the next …
Browse files Browse the repository at this point in the history
…versions that should be upgraded instead of using a simple incrementing integer
  • Loading branch information
filiphr committed Sep 12, 2024
1 parent 3e2eab8 commit d9ff027
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ public boolean equals(Object obj) {
}
}

public record VersionState(FlowableVersion currentVersion, List<FlowableVersion> nextVersions) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FlowableVersion> 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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {
Expand Down Expand Up @@ -132,8 +134,6 @@ public String schemaUpdate() {

protected String schemaUpdateInLock() {
String feedback = null;
boolean isUpgradeNeeded = false;
int matchingVersionIndex = -1;

boolean isEngineTablePresent = isEngineTablePresent();

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit d9ff027

Please sign in to comment.