Browse Source
* ref: migrate diff logic to list api * feat: update frontend resources * fix: checkstylemaster
vran
3 years ago
committed by
GitHub
39 changed files with 625 additions and 149 deletions
@ -1 +1 @@ |
|||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.9effab81.js"></script><script defer="defer" type="module" src="/js/app.bc6973d3.js"></script><link href="/css/chunk-vendors.81898547.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fb0c8458.js" nomodule></script><script defer="defer" src="/js/app-legacy.f8c04b90.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> |
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.9effab81.js"></script><script defer="defer" type="module" src="/js/app.71b7975b.js"></script><link href="/css/chunk-vendors.81898547.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fb0c8458.js" nomodule></script><script defer="defer" src="/js/app-legacy.f7b5df54.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,15 @@ |
|||||
|
package com.databasir.core.domain.document.comparator; |
||||
|
|
||||
|
import com.databasir.core.diff.data.DiffType; |
||||
|
import lombok.Data; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
|
||||
|
@Data |
||||
|
@RequiredArgsConstructor |
||||
|
public class DiffResult { |
||||
|
|
||||
|
private final String id; |
||||
|
|
||||
|
private final DiffType diffType; |
||||
|
|
||||
|
} |
@ -0,0 +1,188 @@ |
|||||
|
package com.databasir.core.domain.document.comparator; |
||||
|
|
||||
|
import com.databasir.core.diff.data.DiffType; |
||||
|
import com.databasir.core.meta.data.*; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import java.util.function.BiFunction; |
||||
|
import java.util.function.Function; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@Slf4j |
||||
|
public class DocumentDiffs { |
||||
|
|
||||
|
public static List<TableDiffResult> tableDiff(DatabaseMeta original, DatabaseMeta current) { |
||||
|
return tableDiff(original.getTables(), current.getTables()); |
||||
|
} |
||||
|
|
||||
|
public static List<TableDiffResult> tableDiff(List<TableMeta> original, List<TableMeta> current) { |
||||
|
Map<String, TableMeta> originalTablesMap = toMap(original, TableMeta::getName); |
||||
|
Map<String, TableMeta> currentTablesMap = toMap(current, TableMeta::getName); |
||||
|
var added = added(originalTablesMap, currentTablesMap) |
||||
|
.stream() |
||||
|
.map(curr -> { |
||||
|
TableDiffResult result = new TableDiffResult(curr.getName(), DiffType.ADDED); |
||||
|
List<DiffResult> columnDiffs = |
||||
|
doDiff(Collections.emptyList(), curr.getColumns(), ColumnMeta::getName); |
||||
|
List<DiffResult> indexDiffs = |
||||
|
doDiff(Collections.emptyList(), curr.getIndexes(), IndexMeta::getName); |
||||
|
List<DiffResult> triggerDiffs = |
||||
|
doDiff(Collections.emptyList(), curr.getTriggers(), TriggerMeta::getName); |
||||
|
List<DiffResult> fkDiffs = |
||||
|
doDiff(Collections.emptyList(), |
||||
|
curr.getForeignKeys(), |
||||
|
fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq()); |
||||
|
result.setColumnDiffResults(columnDiffs); |
||||
|
result.setIndexDiffResults(indexDiffs); |
||||
|
result.setTriggerDiffResults(triggerDiffs); |
||||
|
result.setForeignKeyDiffResults(fkDiffs); |
||||
|
return result; |
||||
|
}) |
||||
|
.collect(Collectors.toList()); |
||||
|
var removed = removed(originalTablesMap, currentTablesMap) |
||||
|
.stream() |
||||
|
.map(old -> { |
||||
|
TableDiffResult result = new TableDiffResult(old.getName(), DiffType.REMOVED); |
||||
|
List<DiffResult> columnDiffs = |
||||
|
doDiff(old.getColumns(), Collections.emptyList(), ColumnMeta::getName); |
||||
|
List<DiffResult> indexDiffs = |
||||
|
doDiff(old.getIndexes(), Collections.emptyList(), IndexMeta::getName); |
||||
|
List<DiffResult> triggerDiffs = |
||||
|
doDiff(old.getTriggers(), Collections.emptyList(), TriggerMeta::getName); |
||||
|
List<DiffResult> fkDiffs = |
||||
|
doDiff(old.getForeignKeys(), |
||||
|
Collections.emptyList(), |
||||
|
fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq()); |
||||
|
result.setColumnDiffResults(columnDiffs); |
||||
|
result.setIndexDiffResults(indexDiffs); |
||||
|
result.setTriggerDiffResults(triggerDiffs); |
||||
|
result.setForeignKeyDiffResults(fkDiffs); |
||||
|
return result; |
||||
|
}) |
||||
|
.collect(Collectors.toList()); |
||||
|
List<TableDiffResult> sameOrModified = currentTablesMap.entrySet() |
||||
|
.stream() |
||||
|
.filter(entry -> originalTablesMap.containsKey(entry.getKey())) |
||||
|
.map(entry -> { |
||||
|
String tableName = entry.getKey(); |
||||
|
TableMeta currentTable = entry.getValue(); |
||||
|
TableMeta originalTable = originalTablesMap.get(tableName); |
||||
|
|
||||
|
List<DiffResult> columnDiffs = |
||||
|
doDiff(originalTable.getColumns(), currentTable.getColumns(), ColumnMeta::getName); |
||||
|
List<DiffResult> indexDiffs = |
||||
|
doDiff(originalTable.getIndexes(), currentTable.getIndexes(), IndexMeta::getName); |
||||
|
List<DiffResult> triggerDiffs = |
||||
|
doDiff(originalTable.getTriggers(), currentTable.getTriggers(), TriggerMeta::getName); |
||||
|
List<DiffResult> fkDiffs = |
||||
|
doDiff(originalTable.getForeignKeys(), |
||||
|
currentTable.getForeignKeys(), |
||||
|
fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq()); |
||||
|
|
||||
|
DiffType diffType = Objects.equals(currentTable, originalTable) ? DiffType.NONE : DiffType.MODIFIED; |
||||
|
TableDiffResult diffResult = new TableDiffResult(tableName, diffType); |
||||
|
diffResult.setColumnDiffResults(columnDiffs); |
||||
|
diffResult.setIndexDiffResults(indexDiffs); |
||||
|
diffResult.setTriggerDiffResults(triggerDiffs); |
||||
|
diffResult.setForeignKeyDiffResults(fkDiffs); |
||||
|
return diffResult; |
||||
|
}) |
||||
|
.collect(Collectors.toList()); |
||||
|
|
||||
|
List<TableDiffResult> all = new ArrayList<>(16); |
||||
|
all.addAll(sameOrModified); |
||||
|
all.addAll(added); |
||||
|
all.addAll(removed); |
||||
|
return all; |
||||
|
} |
||||
|
|
||||
|
private static <T> List<DiffResult> doDiff(List<T> original, List<T> current, Function<T, String> idMapping) { |
||||
|
Map<String, T> originalColumnMap = toMap(original, idMapping); |
||||
|
Map<String, T> currentColumnMap = toMap(current, idMapping); |
||||
|
BiFunction<T, DiffType, DiffResult> mapping = (meta, diffType) -> { |
||||
|
return new DiffResult(idMapping.apply(meta), diffType); |
||||
|
}; |
||||
|
List<DiffResult> added = added(originalColumnMap, currentColumnMap) |
||||
|
.stream() |
||||
|
.map(col -> mapping.apply(col, DiffType.ADDED)) |
||||
|
.collect(Collectors.toList()); |
||||
|
List<DiffResult> removed = removed(originalColumnMap, currentColumnMap) |
||||
|
.stream() |
||||
|
.map(col -> mapping.apply(col, DiffType.REMOVED)) |
||||
|
.collect(Collectors.toList()); |
||||
|
List<DiffResult> modified = modified(originalColumnMap, currentColumnMap) |
||||
|
.stream() |
||||
|
.map(col -> mapping.apply(col, DiffType.MODIFIED)) |
||||
|
.collect(Collectors.toList()); |
||||
|
List<DiffResult> same = same(originalColumnMap, currentColumnMap) |
||||
|
.stream() |
||||
|
.map(col -> mapping.apply(col, DiffType.NONE)) |
||||
|
.collect(Collectors.toList()); |
||||
|
List<DiffResult> columnResults = new ArrayList<>(); |
||||
|
columnResults.addAll(same); |
||||
|
columnResults.addAll(added); |
||||
|
columnResults.addAll(modified); |
||||
|
columnResults.addAll(removed); |
||||
|
return columnResults; |
||||
|
} |
||||
|
|
||||
|
private static <T> Map<String, T> toMap(List<T> content, Function<T, String> idMapping) { |
||||
|
return content |
||||
|
.stream() |
||||
|
.collect(Collectors.toMap(idMapping, Function.identity(), (a, b) -> { |
||||
|
log.warn("Duplicate key, origin = {}, current = {}", a, b); |
||||
|
return a; |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> added(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById) { |
||||
|
return currentMapById.entrySet() |
||||
|
.stream() |
||||
|
.filter(entry -> !originalMapById.containsKey(entry.getKey())) |
||||
|
.map(Map.Entry::getValue) |
||||
|
.collect(Collectors.toList()); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> removed(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById) { |
||||
|
return originalMapById.entrySet() |
||||
|
.stream() |
||||
|
.filter(entry -> !currentMapById.containsKey(entry.getKey())) |
||||
|
.map(Map.Entry::getValue) |
||||
|
.collect(Collectors.toList()); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> modified(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById) { |
||||
|
return modified(originalMapById, currentMapById, Objects::equals); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> modified(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById, |
||||
|
BiFunction<T, T, Boolean> sameFunction) { |
||||
|
return currentMapById.entrySet() |
||||
|
.stream() |
||||
|
.filter(entry -> originalMapById.containsKey(entry.getKey())) |
||||
|
.filter(entry -> !sameFunction.apply(entry.getValue(), originalMapById.get(entry.getKey()))) |
||||
|
.map(Map.Entry::getValue) |
||||
|
.collect(Collectors.toList()); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> same(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById) { |
||||
|
return same(originalMapById, currentMapById, Objects::equals); |
||||
|
} |
||||
|
|
||||
|
private static <T> List<T> same(Map<String, T> originalMapById, |
||||
|
Map<String, T> currentMapById, |
||||
|
BiFunction<T, T, Boolean> sameFunction) { |
||||
|
return currentMapById.entrySet() |
||||
|
.stream() |
||||
|
.filter(entry -> originalMapById.containsKey(entry.getKey())) |
||||
|
.filter(entry -> sameFunction.apply(entry.getValue(), originalMapById.get(entry.getKey()))) |
||||
|
.map(Map.Entry::getValue) |
||||
|
.collect(Collectors.toList()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
package com.databasir.core.domain.document.comparator; |
||||
|
|
||||
|
import com.databasir.core.diff.data.DiffType; |
||||
|
import lombok.Data; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
|
||||
|
import java.util.Collection; |
||||
|
import java.util.Collections; |
||||
|
|
||||
|
@Data |
||||
|
@RequiredArgsConstructor |
||||
|
public class TableDiffResult { |
||||
|
|
||||
|
private final String id; |
||||
|
|
||||
|
private final DiffType diffType; |
||||
|
|
||||
|
private Collection<DiffResult> columnDiffResults = Collections.emptyList(); |
||||
|
|
||||
|
private Collection<DiffResult> indexDiffResults = Collections.emptyList(); |
||||
|
|
||||
|
private Collection<DiffResult> triggerDiffResults = Collections.emptyList(); |
||||
|
|
||||
|
private Collection<DiffResult> foreignKeyDiffResults = Collections.emptyList(); |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package com.databasir.core.domain.document.data; |
||||
|
|
||||
|
import com.databasir.core.diff.data.DiffType; |
||||
|
|
||||
|
public interface DiffAble<T> { |
||||
|
|
||||
|
void setDiffType(DiffType diffType); |
||||
|
|
||||
|
void setOriginal(T t); |
||||
|
} |
||||
|
|
@ -0,0 +1,16 @@ |
|||||
|
package com.databasir.core.domain.document.data; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Collection; |
||||
|
import java.util.Collections; |
||||
|
|
||||
|
@Data |
||||
|
public class TableDocumentRequest { |
||||
|
|
||||
|
private Collection<Integer> tableIds = Collections.emptyList(); |
||||
|
|
||||
|
private Long originalVersion; |
||||
|
|
||||
|
private Long currentVersion; |
||||
|
} |
@ -1 +1 @@ |
|||||
Subproject commit 6dac399b514868bc6be0209da9c4cbb0f8759ca0 |
Subproject commit 5ed5897c7cd9a0f097068c120539037fc5509f3f |
Loading…
Reference in new issue