parent
0a34e3a98b
commit
70d65aa67a
|
@ -108,7 +108,12 @@ public class DocumentService {
|
||||||
eventPublisher.publish(new DocumentUpdated(diff, version + 1, version, projectId));
|
eventPublisher.publish(new DocumentUpdated(diff, version + 1, version, projectId));
|
||||||
} else {
|
} else {
|
||||||
saveNewDocument(current, 1L, projectId);
|
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));
|
eventPublisher.publish(new DocumentUpdated(diff, 1L, null, projectId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.databasir.core.diff.processor;
|
||||||
|
|
||||||
import com.databasir.core.diff.data.DiffType;
|
import com.databasir.core.diff.data.DiffType;
|
||||||
import com.databasir.core.diff.data.FieldDiff;
|
import com.databasir.core.diff.data.FieldDiff;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -12,6 +14,8 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public interface DiffProcessor<T> {
|
public interface DiffProcessor<T> {
|
||||||
|
|
||||||
|
Logger log = LoggerFactory.getLogger(DiffProcessor.class);
|
||||||
|
|
||||||
FieldDiff process(String fieldName, List<T> original, List<T> current);
|
FieldDiff process(String fieldName, List<T> original, List<T> current);
|
||||||
|
|
||||||
default FieldDiff diffTableField(List<T> original,
|
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) {
|
default Map<String, T> toMap(List<T> content, Function<T, String> idMapping) {
|
||||||
return content
|
return content
|
||||||
.stream()
|
.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,
|
default List<FieldDiff> originalRemovedField(Map<String, T> originalMapById,
|
||||||
|
|
|
@ -13,12 +13,6 @@ public class ForeignKeyDiffProcessor implements DiffProcessor<ForeignKeyMeta> {
|
||||||
original,
|
original,
|
||||||
current,
|
current,
|
||||||
"foreignKeys",
|
"foreignKeys",
|
||||||
fk -> {
|
fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq());
|
||||||
if (fk.getFkName() == null) {
|
|
||||||
return fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq();
|
|
||||||
} else {
|
|
||||||
return fk.getFkName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue