Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class Constants {

public static final String DEFAULT_MONGOCK_ORIGIN = "mongockChangeLog";

public static final String MONGOCK_IMPORT_SKIP_PROPERTY_KEY = "internal.mongock.import.skip";
public static final String MONGOCK_IMPORT_ORIGIN_PROPERTY_KEY = "internal.mongock.import.origin";
public static final String MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY = "internal.mongock.import.emptyOriginAllowed";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.flamingock.internal.common.core.audit.AuditWriter;
import io.flamingock.internal.common.core.error.FlamingockException;
import io.flamingock.internal.common.core.pipeline.PipelineDescriptor;
import io.flamingock.internal.common.core.util.ConfigValueParser;
import io.flamingock.internal.core.external.targets.TargetSystemManager;
import io.flamingock.internal.core.external.targets.operations.TargetSystemOps;
import io.flamingock.internal.core.external.targets.operations.TransactionalTargetSystemOps;
Expand All @@ -35,6 +34,7 @@

import static io.flamingock.internal.common.core.audit.AuditReaderType.MONGOCK;
import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY;
import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_SKIP_PROPERTY_KEY;

/**
* This ChangeUnit is intentionally not annotated with @Change, @Apply, or similar,
Expand All @@ -48,7 +48,12 @@ public void importHistory(@Named("change.targetSystem.id") String targetSystemId
@NonLockGuarded TargetSystemManager targetSystemManager,
@NonLockGuarded AuditWriter auditWriter,
@NonLockGuarded PipelineDescriptor pipelineDescriptor,
@Nullable @Named(MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY) String emptyOriginAllowed) {
@Nullable @Named(MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY) String emptyOriginAllowed,
@Nullable @Named(MONGOCK_IMPORT_SKIP_PROPERTY_KEY) String skipImport) {
if (resolveSkipImport(skipImport)) {
logger.info("Mongock audit log import skipped (skipImport=true). No audit entries will be migrated.");
return;
}
logger.info("Starting audit log migration from Mongock to Flamingock community audit store");
AuditHistoryReader legacyHistoryReader = getAuditHistoryReader(targetSystemId, targetSystemManager);
PipelineHelper pipelineHelper = new PipelineHelper(pipelineDescriptor);
Expand Down Expand Up @@ -102,4 +107,15 @@ private boolean resolveEmptyOriginAllowed(String raw) {
throw new FlamingockException("Invalid value for " + MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY + ": " + raw
+ " (expected \"true\" or \"false\" or empty)");
}

private boolean resolveSkipImport(String raw) {
if (raw == null || raw.trim().isEmpty()) {
return false; // default behaviour
}
String v = raw.trim();
if ("true".equalsIgnoreCase(v)) return true;
if ("false".equalsIgnoreCase(v)) return false;
throw new FlamingockException("Invalid value for " + MONGOCK_IMPORT_SKIP_PROPERTY_KEY + ": " + raw
+ " (expected \"true\" or \"false\" or empty)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@
*/
String targetSystem();

/**
* Determines whether Mongock import should be skipped.
* <p>
* Expected literal values are {@code "true"} or {@code "false"}.
* </p>
*
* <p>
* Default value is {@code "false"} (import enabled).
* </p>
*
* @return {@code "true"} to skip import, {@code "false"} to process it
*/
String skipImport() default "false";

/**
* Defines the origin collection/table name where Mongock audit entries are stored.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.stream.Stream;

import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY;
import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_SKIP_PROPERTY_KEY;
import static io.flamingock.internal.common.core.metadata.Constants.MONGOCK_IMPORT_ORIGIN_PROPERTY_KEY;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -84,6 +85,7 @@ public Collection<CodePreviewChange> findAnnotatedChanges() {
.flatMap(List::stream)
.filter(Objects::nonNull)
.collect(Collectors.toList());

changes.add(getImporterChange(mongockTargetSystemId));

return changes;
Expand Down Expand Up @@ -142,16 +144,23 @@ private void processConfigurationProperties(MongockSupport mongockSupport, Map<S
throw new IllegalArgumentException("properties");
}

// Skip Import
ConfigValueParser.ConfigValue skipImportValue =
ConfigValueParser.parse("skipImport", mongockSupport.skipImport(), ConfigValueParser.BOOLEAN_VALUE_VALIDATOR);
if (!skipImportValue.isEmpty()) {
properties.put(MONGOCK_IMPORT_SKIP_PROPERTY_KEY, skipImportValue.getRaw());
}

// Empty Origin Allowed
ConfigValueParser.ConfigValue emptyOriginAllowedValue =
ConfigValueParser.parse(MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY, mongockSupport.emptyOriginAllowed(), ConfigValueParser.BOOLEAN_VALUE_VALIDATOR);
ConfigValueParser.parse("emptyOriginAllowed", mongockSupport.emptyOriginAllowed(), ConfigValueParser.BOOLEAN_VALUE_VALIDATOR);
if (!emptyOriginAllowedValue.isEmpty()) {
properties.put(MONGOCK_IMPORT_EMPTY_ORIGIN_ALLOWED_PROPERTY_KEY, emptyOriginAllowedValue.getRaw());
}

// Origin
ConfigValueParser.ConfigValue originValue =
ConfigValueParser.parse(MONGOCK_IMPORT_ORIGIN_PROPERTY_KEY, mongockSupport.origin());
ConfigValueParser.parse("origin", mongockSupport.origin());
if (!originValue.isEmpty()) {
properties.put(MONGOCK_IMPORT_ORIGIN_PROPERTY_KEY, originValue.getRaw());
}
Expand Down
Loading