Browse Source

fix: sync project error #83 (#84)

master
vran 3 years ago
committed by GitHub
parent
commit
70d65aa67a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java
  2. 9
      plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java
  3. 8
      plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java

7
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));
}
}

9
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<T> {
Logger log = LoggerFactory.getLogger(DiffProcessor.class);
FieldDiff process(String fieldName, List<T> original, List<T> current);
default FieldDiff diffTableField(List<T> original,
@ -41,7 +45,10 @@ public interface DiffProcessor<T> {
default Map<String, T> toMap(List<T> content, Function<T, String> 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<FieldDiff> originalRemovedField(Map<String, T> originalMapById,

8
plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java

@ -13,12 +13,6 @@ public class ForeignKeyDiffProcessor implements DiffProcessor<ForeignKeyMeta> {
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());
}
}

Loading…
Cancel
Save