diff --git a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java index 4013b9f..99c0e8b 100644 --- a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java +++ b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java @@ -108,7 +108,12 @@ public class DocumentService { eventPublisher.publish(new DocumentUpdated(diff, version + 1, version, projectId)); } else { saveNewDocument(current, 1L, projectId); - RootDiff diff = Diffs.diff(null, current); + RootDiff diff = null; + try { + diff = Diffs.diff(null, current); + } catch (Exception e) { + log.error("diff project " + projectId + " error, fallback diff type to NONE", e); + } eventPublisher.publish(new DocumentUpdated(diff, 1L, null, projectId)); } } diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java index 3c69ed3..ce1ebfb 100644 --- a/plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java +++ b/plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java @@ -2,6 +2,8 @@ package com.databasir.core.diff.processor; import com.databasir.core.diff.data.DiffType; import com.databasir.core.diff.data.FieldDiff; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -12,6 +14,8 @@ import java.util.stream.Collectors; public interface DiffProcessor { + Logger log = LoggerFactory.getLogger(DiffProcessor.class); + FieldDiff process(String fieldName, List original, List current); default FieldDiff diffTableField(List original, @@ -41,7 +45,10 @@ public interface DiffProcessor { default Map toMap(List content, Function idMapping) { return content .stream() - .collect(Collectors.toMap(idMapping, Function.identity())); + .collect(Collectors.toMap(idMapping, Function.identity(), (a, b) -> { + log.warn("Duplicate key, origin = {}, current = {}", a, b); + return a; + })); } default List originalRemovedField(Map originalMapById, diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java index 8d8e537..0064613 100644 --- a/plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java +++ b/plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java @@ -13,12 +13,6 @@ public class ForeignKeyDiffProcessor implements DiffProcessor { original, current, "foreignKeys", - fk -> { - if (fk.getFkName() == null) { - return fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq(); - } else { - return fk.getFkName(); - } - }); + fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq()); } }