Skip to content

Commit

Permalink
MID-8842 ninja - DB schema version skip check option + some logging a…
Browse files Browse the repository at this point in the history
…dded (debug level)

(cherry picked from commit 44e334d)
  • Loading branch information
1azyman committed Aug 3, 2023
1 parent 871f469 commit 8843133
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface MidpointConfiguration {
String MIDPOINT_LOGGING_ALT_FILENAME_PROPERTY = "midpoint.logging.alt.filename";
String MIDPOINT_LOGGING_ALT_PREFIX_PROPERTY = "midpoint.logging.alt.prefix";

String MIDPOINT_SKIP_VERSION_CHECK="midpoint.skipVersionCheck";

String USER_HOME_PROPERTY = "user.home";

String MIDPOINT_CONFIG_FILE_PROPERTY = "midpoint.configFile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
import javax.sql.DataSource;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MGlobalMetadata;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QGlobalMetadata;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;

import com.evolveum.midpoint.util.logging.Trace;

import com.evolveum.midpoint.util.logging.TraceManager;

import javax.annotation.PostConstruct;

import javax.sql.DataSource;
import javax.xml.namespace.QName;

import com.querydsl.sql.types.ArrayType;
import com.querydsl.sql.types.EnumAsObjectType;
import org.apache.commons.lang3.BooleanUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -56,6 +67,8 @@
*/
public class SqaleRepoContext extends SqlRepoContext {

private static final Trace LOGGER = TraceManager.getTrace(SqaleRepoContext.class);

private final String schemaChangeNumberLabel;

private final int schemaChangeNumberValue;
Expand Down Expand Up @@ -115,6 +128,14 @@ public SqaleRepoContext(

@PostConstruct
public void initialize() {
// skip version check if option was defined or option value is "true" (equals ignore case)
String skipVersionCheck = System.getProperty(MidpointConfiguration.MIDPOINT_SKIP_VERSION_CHECK + "1");
if ("".equals(skipVersionCheck) || BooleanUtils.isTrue(Boolean.parseBoolean(skipVersionCheck))) {
return;
}

LOGGER.debug("Checking DB schema version.");

try (JdbcSession session = this.newJdbcSession().startReadOnlyTransaction()) {
MGlobalMetadata metadata = session.newQuery().from(QGlobalMetadata.DEFAULT)
.select(QGlobalMetadata.DEFAULT)
Expand All @@ -129,6 +150,8 @@ public void initialize() {
+ ") doesn't match expected value (" + schemaChangeNumberValue + ") for label '" + schemaChangeNumberLabel
+ "'. Seems like mismatch between midPoint executable version and DB schema version. Maybe DB schema was not updated?");
}

LOGGER.debug("DB schema version check OK.");
}

clearCaches();
Expand Down

0 comments on commit 8843133

Please sign in to comment.