Skip to content

Commit

Permalink
fix: table diff is none when index or fk is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
vran-dev committed Dec 1, 2023
1 parent bb2e5a7 commit 633026a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,21 @@ public List<TableDocDiff> diff(List<TableDocDiff> original, List<TableDocDiff> c

BaseTypeFieldEqualFunction eq = new BaseTypeFieldEqualFunction(IGNORE_FIELDS);
DiffType diffType = eq.apply(currentTable, originalTable) ? DiffType.NONE : DiffType.MODIFIED;
boolean indexModified = indexDiffs.stream()
.anyMatch(indexDiff -> indexDiff.getDiffType() != DiffType.NONE);
boolean triggerModified = triggerDiffs.stream()
.anyMatch(triggerDiff -> triggerDiff.getDiffType() != DiffType.NONE);
boolean fkModified = fkDiffs.stream()
.anyMatch(fkDiff -> fkDiff.getDiffType() != DiffType.NONE);
if (indexModified || triggerModified || fkModified) {
diffType = DiffType.MODIFIED;
}

// workaround for diffType = NONE
if (diffType == DiffType.NONE) {
originalTable = null;
}

return TableDocDiff.builder()
.id(currentTable.getId())
.diffType(diffType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.PriorityQueue;

@Slf4j
public class MetaProviders {
Expand Down Expand Up @@ -73,6 +74,7 @@ private static DatabaseMetaProvider mysql() {
}

private static DatabaseMetaProvider sqlServer() {
SqlServerColumnMetaProvider var = new SqlServerColumnMetaProvider();
var columnMetaProvider = new SqlServerColumnMetaProvider();
var foreignKeyMetaProvider = new JdbcForeignKeyMetaProvider();
var indexMetaProvider = new JdbcIndexMetaProvider();
Expand All @@ -87,6 +89,9 @@ private static DatabaseMetaProvider sqlServer() {
}

private static DatabaseMetaProvider postgresql() {
var queue = new PriorityQueue<Integer>();
queue.offer(1);

var columnMetaProvider = new JdbcColumnMetaProvider();
var foreignKeyMetaProvider = new JdbcForeignKeyMetaProvider();
var indexMetaProvider = new JdbcIndexMetaProvider();
Expand Down

0 comments on commit 633026a

Please sign in to comment.