From 2fd588c7b83f91e2999d58bc7be20833488b4328 Mon Sep 17 00:00:00 2001 From: vran Date: Wed, 16 Mar 2022 23:42:38 +0800 Subject: [PATCH] feat: implementation diff processor --- plugin/build.gradle | 2 + .../java/com/databasir/core/diff/Diffs.java | 17 + .../com/databasir/core/diff/data/Diff.java | 11 + .../databasir/core/diff/data/DiffType.java | 9 + .../databasir/core/diff/data/FieldDiff.java | 24 + .../databasir/core/diff/data/RootDiff.java | 15 + .../diff/processor/ColumnDiffProcessor.java | 14 + .../diff/processor/DatabaseDiffProcessor.java | 81 +++ .../core/diff/processor/DiffProcessor.java | 94 +++ .../processor/ForeignKeyDiffProcessor.java | 24 + .../diff/processor/IndexDiffProcessor.java | 14 + .../diff/processor/TableDiffProcessor.java | 122 ++++ .../diff/processor/TriggerDiffProcessor.java | 14 + .../databasir/core/meta/data/ColumnMeta.java | 6 +- .../core/meta/data/DatabaseMeta.java | 4 + .../core/meta/data/ForeignKeyMeta.java | 8 +- .../databasir/core/meta/data/IndexMeta.java | 6 +- .../databasir/core/meta/data/TableMeta.java | 8 +- .../databasir/core/meta/data/TriggerMeta.java | 6 +- .../jdbc/JdbcForeignKeyMetaRepository.java | 2 + plugin/src/test/java/App.java | 28 +- .../core/diff/service/DiffsTest.java | 606 ++++++++++++++++++ .../diffsTest/diffDatabaseAdded/current.json | 466 ++++++++++++++ .../diffsTest/diffDatabaseAdded/original.json | 3 + .../diffDatabaseModified/current.json | 470 ++++++++++++++ .../diffDatabaseModified/original.json | 470 ++++++++++++++ .../diffDatabaseRemoved/current.json | 3 + .../diffDatabaseRemoved/original.json | 466 ++++++++++++++ .../diffsTest/diffDatabaseSame/current.json | 466 ++++++++++++++ .../diffsTest/diffDatabaseSame/original.json | 466 ++++++++++++++ .../ut/diffsTest/diffTableAdded/current.json | 466 ++++++++++++++ .../ut/diffsTest/diffTableAdded/original.json | 328 ++++++++++ .../diffTableFieldsAdded/current.json | 514 +++++++++++++++ .../diffTableFieldsAdded/original.json | 466 ++++++++++++++ .../diffTableFieldsModified/current.json | 474 ++++++++++++++ .../diffTableFieldsModified/original.json | 472 ++++++++++++++ .../diffTableFieldsRemoved/current.json | 428 +++++++++++++ .../diffTableFieldsRemoved/original.json | 474 ++++++++++++++ .../diffsTest/diffTableModified/current.json | 470 ++++++++++++++ .../diffsTest/diffTableModified/original.json | 470 ++++++++++++++ .../diffsTest/diffTableRemoved/current.json | 332 ++++++++++ .../diffsTest/diffTableRemoved/original.json | 470 ++++++++++++++ 42 files changed, 9265 insertions(+), 24 deletions(-) create mode 100644 plugin/src/main/java/com/databasir/core/diff/Diffs.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/data/Diff.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/data/DiffType.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/data/FieldDiff.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/data/RootDiff.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/ColumnDiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/DatabaseDiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/IndexDiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/TableDiffProcessor.java create mode 100644 plugin/src/main/java/com/databasir/core/diff/processor/TriggerDiffProcessor.java create mode 100644 plugin/src/test/java/com/databasir/core/diff/service/DiffsTest.java create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableAdded/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableAdded/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableModified/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableModified/original.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableRemoved/current.json create mode 100644 plugin/src/test/resources/ut/diffsTest/diffTableRemoved/original.json diff --git a/plugin/build.gradle b/plugin/build.gradle index 914243b..722d080 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -2,4 +2,6 @@ dependencies { testImplementation 'mysql:mysql-connector-java:8.0.27' implementation 'org.commonmark:commonmark:0.18.1' implementation 'org.freemarker:freemarker:2.3.31' + testImplementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}" + testImplementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" } diff --git a/plugin/src/main/java/com/databasir/core/diff/Diffs.java b/plugin/src/main/java/com/databasir/core/diff/Diffs.java new file mode 100644 index 0000000..09e1a5f --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/Diffs.java @@ -0,0 +1,17 @@ +package com.databasir.core.diff; + +import com.databasir.core.diff.data.RootDiff; +import com.databasir.core.diff.processor.DatabaseDiffProcessor; +import com.databasir.core.meta.data.DatabaseMeta; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class Diffs { + + private static final DatabaseDiffProcessor databaseDiffProcessor = new DatabaseDiffProcessor(); + + public static RootDiff diff(DatabaseMeta original, DatabaseMeta current) { + return databaseDiffProcessor.process(original, current); + } + +} diff --git a/plugin/src/main/java/com/databasir/core/diff/data/Diff.java b/plugin/src/main/java/com/databasir/core/diff/data/Diff.java new file mode 100644 index 0000000..af247f3 --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/data/Diff.java @@ -0,0 +1,11 @@ +package com.databasir.core.diff.data; + +public interface Diff { + + DiffType getDiffType(); + + Object getOriginal(); + + Object getCurrent(); + +} diff --git a/plugin/src/main/java/com/databasir/core/diff/data/DiffType.java b/plugin/src/main/java/com/databasir/core/diff/data/DiffType.java new file mode 100644 index 0000000..5928ecc --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/data/DiffType.java @@ -0,0 +1,9 @@ +package com.databasir.core.diff.data; + +public enum DiffType { + NONE, ADDED, REMOVED, MODIFIED; + + public static boolean isModified(DiffType type) { + return type != null && type != NONE; + } +} \ No newline at end of file diff --git a/plugin/src/main/java/com/databasir/core/diff/data/FieldDiff.java b/plugin/src/main/java/com/databasir/core/diff/data/FieldDiff.java new file mode 100644 index 0000000..26e2ddf --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/data/FieldDiff.java @@ -0,0 +1,24 @@ +package com.databasir.core.diff.data; + +import lombok.Builder; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Builder +public class FieldDiff implements Diff { + + private String fieldName; + + private DiffType diffType; + + private Object original; + + private Object current; + + @Builder.Default + private List fields = new ArrayList<>(); + +} diff --git a/plugin/src/main/java/com/databasir/core/diff/data/RootDiff.java b/plugin/src/main/java/com/databasir/core/diff/data/RootDiff.java new file mode 100644 index 0000000..d46eb58 --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/data/RootDiff.java @@ -0,0 +1,15 @@ +package com.databasir.core.diff.data; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class RootDiff { + + private DiffType diffType; + + private List fields = new ArrayList<>(); + +} diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/ColumnDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/ColumnDiffProcessor.java new file mode 100644 index 0000000..3695ebb --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/ColumnDiffProcessor.java @@ -0,0 +1,14 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.meta.data.ColumnMeta; + +import java.util.List; + +public class ColumnDiffProcessor implements DiffProcessor { + + @Override + public FieldDiff process(String fieldName, List original, List current) { + return diffTableField(original, current, fieldName, ColumnMeta::getName); + } +} diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/DatabaseDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/DatabaseDiffProcessor.java new file mode 100644 index 0000000..7db581c --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/DatabaseDiffProcessor.java @@ -0,0 +1,81 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.DiffType; +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.diff.data.RootDiff; +import com.databasir.core.meta.data.DatabaseMeta; +import lombok.extern.slf4j.Slf4j; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +@Slf4j +public class DatabaseDiffProcessor { + + private final TableDiffProcessor tableDiffProcessor = new TableDiffProcessor(); + + private static final DatabaseMeta EMPTY = DatabaseMeta.builder().build(); + + public RootDiff process(DatabaseMeta original, DatabaseMeta current) { + DiffType diffType = null; + if (original == null && current != null) { + diffType = DiffType.ADDED; + } + if (original != null && current == null) { + diffType = DiffType.REMOVED; + } + List fields = diffDatabaseFields( + Objects.requireNonNullElse(original, EMPTY), + Objects.requireNonNullElse(current, EMPTY) + ); + boolean isModified = fields.stream().anyMatch(f -> DiffType.isModified(f.getDiffType())); + if (diffType == null) { + diffType = isModified ? DiffType.MODIFIED : DiffType.NONE; + } + RootDiff diff = new RootDiff(); + diff.setFields(fields); + diff.setDiffType(diffType); + return diff; + } + + private List diffDatabaseFields(DatabaseMeta original, DatabaseMeta current) { + Class clazz = DatabaseMeta.class; + Field[] fields = clazz.getDeclaredFields(); + List diffs = new ArrayList<>(32); + // ignore tables diff + Arrays.stream(fields) + .filter(field -> !Objects.equals(field.getName(), "tables")) + .forEach(field -> { + try { + field.setAccessible(true); + Object originalValue = original == null ? null : field.get(original); + Object currentValue = current == null ? null : field.get(current); + if (!Objects.equals(originalValue, currentValue)) { + DiffType diffType; + if (originalValue == null) { + diffType = DiffType.ADDED; + } else if (currentValue == null) { + diffType = DiffType.REMOVED; + } else { + diffType = DiffType.MODIFIED; + } + diffs.add(FieldDiff.builder() + .diffType(diffType) + .fieldName(field.getName()) + .original(originalValue) + .current(currentValue) + .build()); + } + } catch (IllegalAccessException e) { + log.error("diff field failed", e); + } + }); + + FieldDiff tablesField = tableDiffProcessor.process("tables", original.getTables(), current.getTables()); + diffs.add(tablesField); + return diffs; + } +} 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 new file mode 100644 index 0000000..3c69ed3 --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/DiffProcessor.java @@ -0,0 +1,94 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.DiffType; +import com.databasir.core.diff.data.FieldDiff; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +public interface DiffProcessor { + + FieldDiff process(String fieldName, List original, List current); + + default FieldDiff diffTableField(List original, + List current, + String fieldName, + Function identity) { + Map originalMap = toMap(original, identity); + Map currentMap = toMap(current, identity); + List columnFieldDiffs = new ArrayList<>(32); + // removed + List removedFields = originalRemovedField(originalMap, currentMap); + columnFieldDiffs.addAll(removedFields); + // added + List addedFields = currentAddedField(originalMap, currentMap); + columnFieldDiffs.addAll(addedFields); + // modified + List modifiedFields = modifiedField(originalMap, currentMap); + columnFieldDiffs.addAll(modifiedFields); + return FieldDiff.builder() + .fieldName(fieldName) + .diffType(columnFieldDiffs.isEmpty() ? DiffType.NONE : DiffType.MODIFIED) + .fields(columnFieldDiffs) + .build(); + + } + + default Map toMap(List content, Function idMapping) { + return content + .stream() + .collect(Collectors.toMap(idMapping, Function.identity())); + } + + default List originalRemovedField(Map originalMapById, + Map currentMapById) { + return originalMapById.entrySet() + .stream() + .filter(entry -> !currentMapById.containsKey(entry.getKey())) + .map(entry -> FieldDiff.builder() + .fieldName(entry.getKey()) + .original(entry.getValue()) + .diffType(DiffType.REMOVED) + .build()) + .collect(Collectors.toList()); + } + + default List currentAddedField(Map originalMapById, + Map currentMapById) { + return currentMapById.entrySet() + .stream() + .filter(entry -> !originalMapById.containsKey(entry.getKey())) + .map(entry -> FieldDiff.builder() + .fieldName(entry.getKey()) + .current(entry.getValue()) + .diffType(DiffType.ADDED) + .build()) + .collect(Collectors.toList()); + } + + default List modifiedField(Map original, + Map current) { + List diff = new ArrayList<>(); + original.entrySet() + .stream() + .filter(entry -> current.containsKey(entry.getKey())) + .forEach(entry -> { + T originalValue = entry.getValue(); + T currentValue = current.get(entry.getKey()); + if (!Objects.equals(originalValue, currentValue)) { + FieldDiff fieldDiff = FieldDiff.builder() + .fieldName(entry.getKey()) + .original(originalValue) + .current(currentValue) + .diffType(DiffType.MODIFIED) + .build(); + diff.add(fieldDiff); + } + }); + return diff; + } +} 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 new file mode 100644 index 0000000..59f2d1a --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/ForeignKeyDiffProcessor.java @@ -0,0 +1,24 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.meta.data.ForeignKeyMeta; + +import java.util.List; + +public class ForeignKeyDiffProcessor implements DiffProcessor { + + @Override + public FieldDiff process(String fieldName, List original, List current) { + return diffTableField( + original, + current, + "foreignKeys", + fk -> { + if (fk.getFkName() == null) { + return fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySql(); + } else { + return fk.getFkName(); + } + }); + } +} diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/IndexDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/IndexDiffProcessor.java new file mode 100644 index 0000000..0d5cdf1 --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/IndexDiffProcessor.java @@ -0,0 +1,14 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.meta.data.IndexMeta; + +import java.util.List; + +public class IndexDiffProcessor implements DiffProcessor { + + @Override + public FieldDiff process(String fieldName, List original, List current) { + return diffTableField(original, current, fieldName, IndexMeta::getName); + } +} diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/TableDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/TableDiffProcessor.java new file mode 100644 index 0000000..b991041 --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/TableDiffProcessor.java @@ -0,0 +1,122 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.DiffType; +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.meta.data.TableMeta; +import lombok.extern.slf4j.Slf4j; + +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +public class TableDiffProcessor implements DiffProcessor { + + private final IndexDiffProcessor indexDiffProcessor = new IndexDiffProcessor(); + + private final ColumnDiffProcessor columnDiffProcessor = new ColumnDiffProcessor(); + + private final TriggerDiffProcessor triggerDiffProcessor = new TriggerDiffProcessor(); + + private final ForeignKeyDiffProcessor foreignKeyDiffProcessor = new ForeignKeyDiffProcessor(); + + @Override + public FieldDiff process(String fieldName, List original, List current) { + // diff tables field + Map originalMap = toMap(original, TableMeta::getName); + Map currentMap = toMap(current, TableMeta::getName); + List tables = new ArrayList<>(32); + // removed + List removedFields = originalRemovedField(originalMap, currentMap); + tables.addAll(removedFields); + // added + List addedFields = currentAddedField(originalMap, currentMap); + tables.addAll(addedFields); + // modified + List modified = originalMap.entrySet() + .stream() + .filter(entry -> currentMap.containsKey(entry.getKey())) + .filter(entry -> !Objects.equals(entry.getValue(), currentMap.get(entry.getKey()))) + .map(entry -> { + TableMeta originalValue = entry.getValue(); + TableMeta currentValue = currentMap.get(entry.getKey()); + return diffTableField(originalValue, currentValue); + }) + .collect(Collectors.toList()); + tables.addAll(modified); + DiffType tablesDiffType; + if (!modified.isEmpty()) { + tablesDiffType = DiffType.MODIFIED; + } else if (!addedFields.isEmpty()) { + tablesDiffType = DiffType.ADDED; + } else if (!removedFields.isEmpty()) { + tablesDiffType = DiffType.REMOVED; + } else { + tablesDiffType = DiffType.NONE; + } + FieldDiff tablesField = FieldDiff.builder() + .diffType(tablesDiffType) + .fieldName(fieldName) + .fields(tables) + .build(); + return tablesField; + } + + private FieldDiff diffTableField(TableMeta original, TableMeta current) { + FieldDiff columns = + columnDiffProcessor.process("columns", original.getColumns(), current.getColumns()); + FieldDiff indexes = + indexDiffProcessor.process("indexes", original.getIndexes(), current.getIndexes()); + FieldDiff triggers = + triggerDiffProcessor.process("triggers", original.getTriggers(), current.getTriggers()); + FieldDiff foreignKeys = + foreignKeyDiffProcessor.process("foreignKeys", original.getForeignKeys(), current.getForeignKeys()); + List otherFields = fields(original, current); + + List fields = new ArrayList<>(); + fields.add(columns); + fields.add(indexes); + fields.add(foreignKeys); + fields.add(triggers); + fields.addAll(otherFields); + return FieldDiff.builder() + .diffType(DiffType.MODIFIED) + .fieldName(original.getName()) + .fields(fields) + .build(); + } + + private List fields(TableMeta original, TableMeta current) { + List fields = new ArrayList<>(); + // ignore tables diff + Class clazz = TableMeta.class; + List ignoredFields = List.of("columns", "indexes", "triggers", "foreignKeys"); + Arrays.stream(clazz.getDeclaredFields()) + .filter(field -> !ignoredFields.contains(field.getName())) + .forEach(field -> { + try { + field.setAccessible(true); + Object originalValue = original == null ? null : field.get(original); + Object currentValue = current == null ? null : field.get(current); + if (!Objects.equals(originalValue, currentValue)) { + DiffType diffType; + if (originalValue == null) { + diffType = DiffType.ADDED; + } else if (currentValue == null) { + diffType = DiffType.REMOVED; + } else { + diffType = DiffType.MODIFIED; + } + fields.add(FieldDiff.builder() + .diffType(diffType) + .fieldName(field.getName()) + .original(originalValue) + .current(currentValue) + .build()); + } + } catch (IllegalAccessException e) { + log.error("diff field failed", e); + } + }); + return fields; + } +} diff --git a/plugin/src/main/java/com/databasir/core/diff/processor/TriggerDiffProcessor.java b/plugin/src/main/java/com/databasir/core/diff/processor/TriggerDiffProcessor.java new file mode 100644 index 0000000..402125c --- /dev/null +++ b/plugin/src/main/java/com/databasir/core/diff/processor/TriggerDiffProcessor.java @@ -0,0 +1,14 @@ +package com.databasir.core.diff.processor; + +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.meta.data.TriggerMeta; + +import java.util.List; + +public class TriggerDiffProcessor implements DiffProcessor { + + @Override + public FieldDiff process(String fieldName, List original, List current) { + return diffTableField(original, current, fieldName, TriggerMeta::getName); + } +} diff --git a/plugin/src/main/java/com/databasir/core/meta/data/ColumnMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/ColumnMeta.java index b3b0e16..b008694 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/ColumnMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/ColumnMeta.java @@ -1,10 +1,14 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; -@Data @Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class ColumnMeta { private String name; diff --git a/plugin/src/main/java/com/databasir/core/meta/data/DatabaseMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/DatabaseMeta.java index 13091fa..faea56a 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/DatabaseMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/DatabaseMeta.java @@ -1,12 +1,16 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.Collections; import java.util.List; @Data +@NoArgsConstructor +@AllArgsConstructor @Builder public class DatabaseMeta { diff --git a/plugin/src/main/java/com/databasir/core/meta/data/ForeignKeyMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/ForeignKeyMeta.java index 2122f29..65a4307 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/ForeignKeyMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/ForeignKeyMeta.java @@ -1,12 +1,18 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; -@Data @Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class ForeignKeyMeta { + private Integer keySql; + /** * may null */ diff --git a/plugin/src/main/java/com/databasir/core/meta/data/IndexMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/IndexMeta.java index db700ca..69ecb1f 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/IndexMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/IndexMeta.java @@ -1,13 +1,17 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.Collections; import java.util.List; -@Data @Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class IndexMeta { private String name; diff --git a/plugin/src/main/java/com/databasir/core/meta/data/TableMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/TableMeta.java index 0023fe7..ec7d092 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/TableMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/TableMeta.java @@ -1,13 +1,17 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.Collections; import java.util.List; -@Data @Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class TableMeta { private String name; @@ -27,6 +31,4 @@ public class TableMeta { @Builder.Default private List foreignKeys = Collections.emptyList(); - - private String remark; } diff --git a/plugin/src/main/java/com/databasir/core/meta/data/TriggerMeta.java b/plugin/src/main/java/com/databasir/core/meta/data/TriggerMeta.java index 1b9291f..bff3e9a 100644 --- a/plugin/src/main/java/com/databasir/core/meta/data/TriggerMeta.java +++ b/plugin/src/main/java/com/databasir/core/meta/data/TriggerMeta.java @@ -1,13 +1,17 @@ package com.databasir.core.meta.data; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; /** * now: only support mysql, postgresql. */ -@Data @Builder +@Data +@NoArgsConstructor +@AllArgsConstructor public class TriggerMeta { private String name; diff --git a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcForeignKeyMetaRepository.java b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcForeignKeyMetaRepository.java index 0e0790a..7c51ecd 100644 --- a/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcForeignKeyMetaRepository.java +++ b/plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcForeignKeyMetaRepository.java @@ -41,8 +41,10 @@ public class JdbcForeignKeyMetaRepository implements ForeignKeyMetaRepository { String pkColumnName = keyResult.getString("PKCOLUMN_NAME"); String pkName = keyResult.getString("PK_NAME"); int updateRule = keyResult.getInt("UPDATE_RULE"); + int keySql = keyResult.getInt("KEY_SEQ"); int deleteRule = keyResult.getInt("DELETE_RULE"); ForeignKeyMeta meta = ForeignKeyMeta.builder() + .keySql(keySql) .fkTableName(fkTableName) .fkColumnName(fkColumnName) .fkName(fkName) diff --git a/plugin/src/test/java/App.java b/plugin/src/test/java/App.java index 2c0452a..4f884ef 100644 --- a/plugin/src/test/java/App.java +++ b/plugin/src/test/java/App.java @@ -1,9 +1,3 @@ -import com.databasir.core.Databasir; -import com.databasir.core.meta.data.DatabaseMeta; -import org.junit.jupiter.api.Test; - -import java.io.FileOutputStream; -import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -11,17 +5,17 @@ import java.util.Properties; public class App { - @Test - public void testRenderAsMarkdown() throws SQLException, ClassNotFoundException { - try (FileOutputStream out = new FileOutputStream("demo.md")) { - Connection connection = getJdbcConnection(); - Databasir databasir = Databasir.of(); - DatabaseMeta doc = databasir.get(connection, "demo").orElseThrow(); - databasir.renderAsMarkdown(doc, out); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } +// @Test +// public void testRenderAsMarkdown() throws SQLException, ClassNotFoundException { +// try (FileOutputStream out = new FileOutputStream("demo.md")) { +// Connection connection = getJdbcConnection(); +// Databasir databasir = Databasir.of(); +// DatabaseMeta doc = databasir.get(connection, "demo").orElseThrow(); +// databasir.renderAsMarkdown(doc, out); +// } catch (IOException e) { +// throw new IllegalStateException(e); +// } +// } private static Connection getJdbcConnection() throws SQLException, ClassNotFoundException { // get database connection diff --git a/plugin/src/test/java/com/databasir/core/diff/service/DiffsTest.java b/plugin/src/test/java/com/databasir/core/diff/service/DiffsTest.java new file mode 100644 index 0000000..6e50808 --- /dev/null +++ b/plugin/src/test/java/com/databasir/core/diff/service/DiffsTest.java @@ -0,0 +1,606 @@ +package com.databasir.core.diff.service; + +import com.databasir.core.diff.Diffs; +import com.databasir.core.diff.data.DiffType; +import com.databasir.core.diff.data.FieldDiff; +import com.databasir.core.diff.data.RootDiff; +import com.databasir.core.meta.data.*; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TimeZone; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +class DiffsTest { + + private static ObjectMapper objectMapper; + + @BeforeAll + static void init() { + objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS) + .disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS) + .setTimeZone(TimeZone.getDefault()); + } + + @Test + void diffEmptyDatabaseSame() { + DatabaseMeta original = DatabaseMeta.builder().build(); + DatabaseMeta current = DatabaseMeta.builder().build(); + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.NONE, diff.getDiffType()); + } + + @Test + void diffDatabaseSame() { + DatabaseMeta original = load("ut/diffsTest/diffDatabaseSame/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffDatabaseSame/current.json"); + + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.NONE, diff.getDiffType()); + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.NONE, tableField.getDiffType()); + assertTrue(tableField.getFields().isEmpty()); + } + + @Test + void diffDatabaseAdded() { + DatabaseMeta current = load("ut/diffsTest/diffDatabaseAdded/current.json"); + RootDiff diff = Diffs.diff(null, current); + assertEquals(DiffType.ADDED, diff.getDiffType()); + } + + @Test + void diffDatabaseRemoved() { + DatabaseMeta original = load("ut/diffsTest/diffDatabaseRemoved/original.json"); + RootDiff diff = Diffs.diff(original, null); + assertEquals(DiffType.REMOVED, diff.getDiffType()); + } + + @Test + void diffDatabaseModified() { + DatabaseMeta original = load("ut/diffsTest/diffDatabaseModified/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffDatabaseModified/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + assertSame(2, diff.getFields().size()); + Map diffMap = diff.getFields() + .stream() + .collect(Collectors.toMap(d -> d.getFieldName(), Function.identity())); + + // productVersion + assertTrue(diffMap.containsKey("productVersion")); + assertIsModified(diffMap.get("productVersion")); + assertEquals(original.getProductVersion(), diffMap.get("productVersion").getOriginal()); + assertEquals(current.getProductVersion(), diffMap.get("productVersion").getCurrent()); + + // tables + assertTrue(diffMap.containsKey("tables")); + assertIsNone(diffMap.get("tables")); + assertTrue(diffMap.get("tables").getFields().isEmpty()); + } + + @Test + void diffTableAdded() { + DatabaseMeta original = load("ut/diffsTest/diffTableAdded/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableAdded/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + // add table: departments, dept_emp + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.ADDED, tableField.getDiffType()); + + // tables without original & current value + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // add two tables + assertSame(2, tableField.getFields().size()); + Map tableFieldMap = tableField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + Map currentTablesMap = current.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + + List.of("departments", "dept_emp").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff departments = tableFieldMap.get(tableName); + assertIsAdded(departments); + assertNull(departments.getOriginal()); + assertNotNull(departments.getCurrent()); + assertEquals(currentTablesMap.get(tableName), departments.getCurrent()); + }); + } + + @Test + void diffTableRemoved() { + DatabaseMeta original = load("ut/diffsTest/diffTableRemoved/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableRemoved/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + // remove table: departments, dept_emp + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.REMOVED, tableField.getDiffType()); + + // tables without original & current value + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // remove two tables + assertSame(2, tableField.getFields().size()); + Map tableFieldMap = tableField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + Map originalTablesMap = original.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + + List.of("departments", "dept_emp").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff field = tableFieldMap.get(tableName); + assertIsRemoved(field); + assertNull(field.getCurrent()); + assertNotNull(field.getOriginal()); + assertEquals(originalTablesMap.get(tableName), field.getOriginal()); + }); + } + + @Test + void diffTableModified() { + DatabaseMeta original = load("ut/diffsTest/diffTableModified/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableModified/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + /** + * modify three table: departments, dept_emp + * - dept_manager: add comment, change table type + * - departments: add comment + * - dept_emp: add comment + */ + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.MODIFIED, tableField.getDiffType()); + + // tables without original & current value + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // modify 3 tables + assertSame(3, tableField.getFields().size()); + Map tableFieldMap = tableField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + Map originalTableMap = original.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + Map currentTableMap = current.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + + /** + * - departments: add comment + * - dept_emp: add comment + * - dept_manager: add comment, change table type + */ + List.of("departments", "dept_emp", "dept_manager").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff departments = tableFieldMap.get(tableName); + assertIsModified(departments); + assertNull(departments.getCurrent()); + assertNull(departments.getOriginal()); + if ("dept_manager".equals(tableName)) { + // columns \ indexes \ triggers \ forgienKes \ comment + assertSame(6, departments.getFields().size()); + FieldDiff departmentCommentField = departments.getFields().stream() + .filter(f -> f.getFieldName().equals("type")) + .findAny() + .orElseThrow(); + assertEquals(originalTableMap.get(tableName).getType(), departmentCommentField.getOriginal()); + assertEquals(currentTableMap.get(tableName).getType(), departmentCommentField.getCurrent()); + } else { + // columns \ indexes \ triggers \ forgienKes \ comment + assertSame(5, departments.getFields().size()); + } + + FieldDiff departmentCommentField = departments.getFields().stream() + .filter(f -> f.getFieldName().equals("comment")) + .findAny() + .orElseThrow(); + assertEquals(originalTableMap.get(tableName).getComment(), departmentCommentField.getOriginal()); + assertEquals(currentTableMap.get(tableName).getComment(), departmentCommentField.getCurrent()); + }); + } + + /** + * add columns \ indexes \ triggers \ foreignKeys + *

+ * department: + * - add column [deleted], [dept_code] + * - add index [dept_deleted] + * - add triggers [before_insert] + * - add foreignKeys [dept_emp_ibfk_1] + *

+ */ + @Test + void diffTableFieldsAdded() { + DatabaseMeta original = load("ut/diffsTest/diffTableFieldsAdded/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableFieldsAdded/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + // modified table: departments + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.MODIFIED, tableField.getDiffType()); + + // tables without original & current value + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // modified 1 tables + assertSame(1, tableField.getFields().size()); + Map tableFieldMap = tableField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + TableMeta currentDepartment = current.getTables() + .stream() + .filter(t -> "departments".equals(t.getName())) + .findFirst() + .orElseThrow(); + + List.of("departments").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff departments = tableFieldMap.get(tableName); + assertIsModified(departments); + assertNull(departments.getOriginal()); + assertNull(departments.getCurrent()); + + // columns / indexes / triggers / foreignKes + assertSame(4, departments.getFields().size()); + for (FieldDiff field : departments.getFields()) { + assertIsModified(field); + if ("columns".equals(field.getFieldName())) { + assertSame(2, field.getFields().size()); + for (FieldDiff columnField : field.getFields()) { + assertIsAdded(columnField); + assertNull(columnField.getOriginal()); + assertNotNull(columnField.getCurrent()); + ColumnMeta colMeta = (ColumnMeta) columnField.getCurrent(); + boolean matched = currentDepartment.getColumns().stream() + .anyMatch(idx -> Objects.equals(idx, colMeta)); + assertTrue(matched); + } + } + if ("indexes".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff indexes = field.getFields().iterator().next(); + assertIsAdded(indexes); + assertNull(indexes.getOriginal()); + IndexMeta index = (IndexMeta) indexes.getCurrent(); + assertNotNull(index); + boolean matched = currentDepartment.getIndexes().stream() + .anyMatch(idx -> Objects.equals(idx, index)); + assertTrue(matched); + } + if ("triggers".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff triggers = field.getFields().iterator().next(); + assertIsAdded(triggers); + assertNull(triggers.getOriginal()); + TriggerMeta tg = (TriggerMeta) triggers.getCurrent(); + assertNotNull(tg); + boolean matched = currentDepartment.getTriggers().stream().anyMatch(t -> Objects.equals(t, tg)); + assertTrue(matched); + } + if ("foreignKeys".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff foreignKeys = field.getFields().iterator().next(); + assertIsAdded(foreignKeys); + assertNull(foreignKeys.getOriginal()); + ForeignKeyMeta fk = (ForeignKeyMeta) foreignKeys.getCurrent(); + assertNotNull(fk); + boolean matched = currentDepartment.getForeignKeys().stream().anyMatch(f -> Objects.equals(f, fk)); + assertTrue(matched); + } + } + }); + } + + /** + * dept_emp + * fk: dept_emp_ibfk_2 + * column: from_date, to_date + * index: dept_no + * trigger: before_insert + */ + @Test + void diffTableFieldsRemoved() { + DatabaseMeta original = load("ut/diffsTest/diffTableFieldsRemoved/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableFieldsRemoved/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + // modified table: departments + assertSame(1, diff.getFields().size()); + FieldDiff tableField = diff.getFields().iterator().next(); + assertEquals("tables", tableField.getFieldName()); + assertEquals(DiffType.MODIFIED, tableField.getDiffType()); + + // tables without original & current value + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // modified 1 tables + assertSame(1, tableField.getFields().size()); + Map tableFieldMap = tableField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + TableMeta originalTable = original.getTables() + .stream() + .filter(t -> "dept_emp".equals(t.getName())) + .findFirst() + .orElseThrow(); + + /** + * dept_emp + * fk: dept_emp_ibfk_2 + * column: from_date, to_date + * index: dept_no + * trigger: before_insert + */ + List.of("dept_emp").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff departments = tableFieldMap.get(tableName); + assertIsModified(departments); + assertNull(departments.getOriginal()); + assertNull(departments.getCurrent()); + + // columns / indexes / triggers / foreignKes + assertSame(4, departments.getFields().size()); + for (FieldDiff field : departments.getFields()) { + assertIsModified(field); + if ("columns".equals(field.getFieldName())) { + assertSame(2, field.getFields().size()); + for (FieldDiff columnField : field.getFields()) { + assertIsRemoved(columnField); + assertNull(columnField.getCurrent()); + assertNotNull(columnField.getOriginal()); + ColumnMeta colMeta = (ColumnMeta) columnField.getOriginal(); + boolean matched = originalTable.getColumns().stream() + .anyMatch(idx -> Objects.equals(idx, colMeta)); + assertTrue(matched); + } + } + if ("indexes".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff indexes = field.getFields().iterator().next(); + assertIsRemoved(indexes); + assertNull(indexes.getCurrent()); + IndexMeta index = (IndexMeta) indexes.getOriginal(); + assertNotNull(index); + boolean matched = originalTable.getIndexes().stream() + .anyMatch(idx -> Objects.equals(idx, index)); + assertTrue(matched); + } + if ("triggers".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff triggers = field.getFields().iterator().next(); + assertIsRemoved(triggers); + assertNull(triggers.getCurrent()); + TriggerMeta tg = (TriggerMeta) triggers.getOriginal(); + assertNotNull(tg); + boolean matched = originalTable.getTriggers().stream().anyMatch(t -> Objects.equals(t, tg)); + assertTrue(matched); + } + if ("foreignKeys".equals(field.getFieldName())) { + assertSame(1, field.getFields().size()); + FieldDiff foreignKeys = field.getFields().iterator().next(); + assertIsRemoved(foreignKeys); + assertNull(foreignKeys.getCurrent()); + ForeignKeyMeta fk = (ForeignKeyMeta) foreignKeys.getOriginal(); + assertNotNull(fk); + boolean matched = originalTable.getForeignKeys().stream().anyMatch(f -> Objects.equals(f, fk)); + assertTrue(matched); + } + } + }); + } + + @Test + void diffTableFieldsModified() { + DatabaseMeta original = load("ut/diffsTest/diffTableFieldsModified/original.json"); + DatabaseMeta current = load("ut/diffsTest/diffTableFieldsModified/current.json"); + + // database + RootDiff diff = Diffs.diff(original, current); + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + + // modified table: departments, dept_emp + assertSame(1, diff.getFields().size()); + FieldDiff tablesField = diff.getFields().iterator().next(); + assertEquals("tables", tablesField.getFieldName()); + assertEquals(DiffType.MODIFIED, tablesField.getDiffType()); + + // tables without original & current value + assertNull(tablesField.getOriginal()); + assertNull(tablesField.getCurrent()); + + // modified 1 tables + assertSame(2, tablesField.getFields().size()); + Map tableFieldMap = tablesField.getFields() + .stream() + .collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity())); + Map originalTaleMap = original.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + Map currentTableMap = current.getTables() + .stream() + .collect(Collectors.toMap(TableMeta::getName, Function.identity())); + + /** + * departments + * column: dept_no add comment + * column: dept_name add comment + * indexes: dept_name change unique=false + * + * dept_emp + * column: emp_no change default value + * column: dept_noL change auto increment true + * indexes: dept_no + * triggers: before_insert + * foreignKeys: dept_emp_ibfk_2 + */ + List.of("departments", "dept_emp").forEach(tableName -> { + assertTrue(tableFieldMap.containsKey(tableName)); + FieldDiff tableField = tableFieldMap.get(tableName); + assertIsModified(tableField); + assertNull(tableField.getOriginal()); + assertNull(tableField.getCurrent()); + + // columns / indexes / triggers / foreignKes + assertSame(4, tableField.getFields().size()); + for (FieldDiff field : tableField.getFields()) { + if ("columns".equals(field.getFieldName())) { + assertIsModified(field); + assertSame(2, field.getFields().size()); + for (FieldDiff columnField : field.getFields()) { + assertIsModified(columnField); + assertNotNull(columnField.getCurrent()); + assertNotNull(columnField.getOriginal()); + ColumnMeta originalCol = (ColumnMeta) columnField.getOriginal(); + boolean matched = originalTaleMap.get(tableName) + .getColumns() + .stream() + .anyMatch(idx -> Objects.equals(idx, originalCol)); + assertTrue(matched); + + ColumnMeta currentCol = (ColumnMeta) columnField.getCurrent(); + assertTrue(currentTableMap.get(tableName) + .getColumns() + .stream() + .anyMatch(idx -> Objects.equals(idx, currentCol))); + } + } + if ("indexes".equals(field.getFieldName())) { + assertIsModified(field); + assertSame(1, field.getFields().size()); + FieldDiff indexes = field.getFields().iterator().next(); + assertIsModified(indexes); + assertNotNull(indexes.getCurrent()); + assertNotNull(indexes.getOriginal()); + + IndexMeta originalIndex = (IndexMeta) indexes.getOriginal(); + boolean matched = originalTaleMap.get(tableName) + .getIndexes() + .stream() + .anyMatch(idx -> Objects.equals(idx, originalIndex)); + assertTrue(matched); + + IndexMeta currentIndex = (IndexMeta) indexes.getCurrent(); + assertTrue(currentTableMap.get(tableName) + .getIndexes() + .stream() + .anyMatch(idx -> Objects.equals(idx, currentIndex))); + } + if (tableName.equals("dept_emp") && "triggers".equals(field.getFieldName())) { + assertIsModified(field); + assertSame(1, field.getFields().size()); + FieldDiff triggers = field.getFields().iterator().next(); + assertIsModified(triggers); + assertNotNull(triggers.getCurrent()); + assertNotNull(triggers.getOriginal()); + TriggerMeta originalTg = (TriggerMeta) triggers.getOriginal(); + assertTrue(originalTaleMap.get(tableName).getTriggers().stream() + .anyMatch(t -> Objects.equals(t, originalTg))); + + TriggerMeta currentTg = (TriggerMeta) triggers.getCurrent(); + assertTrue(currentTableMap.get(tableName).getTriggers().stream() + .anyMatch(t -> Objects.equals(t, currentTg))); + } + if (tableName.equals("dept_emp") && "foreignKeys".equals(field.getFieldName())) { + assertIsModified(field); + assertSame(1, field.getFields().size()); + FieldDiff foreignKeys = field.getFields().iterator().next(); + assertIsModified(foreignKeys); + assertNotNull(foreignKeys.getCurrent()); + assertNotNull(foreignKeys.getOriginal()); + ForeignKeyMeta originalFk = (ForeignKeyMeta) foreignKeys.getOriginal(); + assertTrue(originalTaleMap.get(tableName) + .getForeignKeys().stream().anyMatch(f -> Objects.equals(f, originalFk))); + + ForeignKeyMeta currentFk = (ForeignKeyMeta) foreignKeys.getCurrent(); + assertTrue(currentTableMap.get(tableName) + .getForeignKeys().stream().anyMatch(f -> Objects.equals(f, currentFk))); + } + if (tableName.equals("departments") && List.of("foreignKeys", "triggers").contains(field.getFieldName())) { + assertIsNone(field); + } + } + }); + } + + private void assertIsModified(FieldDiff diff) { + assertEquals(DiffType.MODIFIED, diff.getDiffType()); + } + + private void assertIsNone(FieldDiff diff) { + assertEquals(DiffType.NONE, diff.getDiffType()); + } + + private void assertIsRemoved(FieldDiff diff) { + assertEquals(DiffType.REMOVED, diff.getDiffType()); + } + + private void assertIsAdded(FieldDiff diff) { + assertEquals(DiffType.ADDED, diff.getDiffType()); + } + + private DatabaseMeta load(String url) { + URL originalUrl = Thread.currentThread().getContextClassLoader() + .getResource(url); + try { + return objectMapper.readValue(originalUrl, DatabaseMeta.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/current.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/current.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/current.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/original.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/original.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseAdded/original.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/current.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/current.json new file mode 100644 index 0000000..cc9f91b --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/current.json @@ -0,0 +1,470 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "8.0.26", + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/original.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/original.json new file mode 100644 index 0000000..38c3b70 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseModified/original.json @@ -0,0 +1,470 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "9.0", + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/current.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/current.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/current.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/original.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/original.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseRemoved/original.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/current.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/current.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/current.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/original.json b/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/original.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffDatabaseSame/original.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableAdded/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableAdded/current.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableAdded/current.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableAdded/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableAdded/original.json new file mode 100644 index 0000000..3a364d0 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableAdded/original.json @@ -0,0 +1,328 @@ +{ + "tables": [ + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/current.json new file mode 100644 index 0000000..a44c1d3 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/current.json @@ -0,0 +1,514 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_code", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "deleted", + "type": "bool", + "size": 1, + "decimalDigits": 1, + "comment": "delete flag", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": 1 + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "dept_deleted", + "isUniqueKey": false, + "columnNames": [ + "deleted" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [ + { + "name": "before_insert", + "timing": "BEFORE", + "manipulation": "INSERT", + "statement": "set null", + "createAt": "2022-01-01" + } + ] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/original.json new file mode 100644 index 0000000..f188af4 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsAdded/original.json @@ -0,0 +1,466 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/current.json new file mode 100644 index 0000000..8c4212b --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/current.json @@ -0,0 +1,474 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "department unique no", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "department unique name", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": false, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": -1 + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "YES", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "NONE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [ + { + "name": "before_insert", + "timing": "AFTER", + "manipulation": "INSERT", + "statement": "set null", + "createAt": "2022-01-01" + } + ] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/original.json new file mode 100644 index 0000000..2ace006 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsModified/original.json @@ -0,0 +1,472 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [{ + "name": "before_insert", + "timing": "BEFORE", + "manipulation": "INSERT", + "statement": "set null", + "createAt": "2022-01-01" + }] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/current.json new file mode 100644 index 0000000..4c4847f --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/current.json @@ -0,0 +1,428 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/original.json new file mode 100644 index 0000000..c702e3e --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableFieldsRemoved/original.json @@ -0,0 +1,474 @@ +{ + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [ + { + "name": "before_insert", + "timing": "BEFORE", + "manipulation": "INSERT", + "statement": "set null", + "createAt": "2022-01-01" + } + ] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableModified/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableModified/current.json new file mode 100644 index 0000000..ea782cf --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableModified/current.json @@ -0,0 +1,470 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "9.0", + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "部门信息", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "员工部门关系", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE2", + "comment": "部门经理关系", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableModified/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableModified/original.json new file mode 100644 index 0000000..38c3b70 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableModified/original.json @@ -0,0 +1,470 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "9.0", + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/current.json b/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/current.json new file mode 100644 index 0000000..23be52e --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/current.json @@ -0,0 +1,332 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "9.0", + "tables": [ + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file diff --git a/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/original.json b/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/original.json new file mode 100644 index 0000000..38c3b70 --- /dev/null +++ b/plugin/src/test/resources/ut/diffsTest/diffTableRemoved/original.json @@ -0,0 +1,470 @@ +{ + "databaseName": "employees", + "schemaName": "employees", + "productName": "MySQL", + "productVersion": "9.0", + "tables": [ + { + "name": "departments", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_name", + "type": "VARCHAR", + "size": 40, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_name", + "isUniqueKey": true, + "columnNames": [ + "dept_name" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "dept_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "dept_emp", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_emp_ibfk_2", + "fkTableName": "dept_emp", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_emp_ibfk_1", + "fkTableName": "dept_emp", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "dept_manager", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "dept_no", + "type": "CHAR", + "size": 4, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "dept_no", + "isUniqueKey": false, + "columnNames": [ + "dept_no" + ] + }, + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "dept_no" + ] + } + ], + "foreignKeys": [ + { + "fkName": "dept_manager_ibfk_2", + "fkTableName": "dept_manager", + "fkColumnName": "dept_no", + "pkName": "PRIMARY", + "pkTableName": "departments", + "pkColumnName": "dept_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + }, + { + "fkName": "dept_manager_ibfk_1", + "fkTableName": "dept_manager", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "employees", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "birth_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "first_name", + "type": "VARCHAR", + "size": 14, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "last_name", + "type": "VARCHAR", + "size": 16, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "gender", + "type": "ENUM", + "size": 1, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "hire_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no" + ] + } + ], + "foreignKeys": [], + "triggers": [] + }, + { + "name": "salaries", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "salary", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "salaries_ibfk_1", + "fkTableName": "salaries", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + }, + { + "name": "titles", + "type": "TABLE", + "comment": "", + "columns": [ + { + "name": "emp_no", + "type": "INT", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "title", + "type": "VARCHAR", + "size": 50, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "from_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": true, + "nullable": "NO", + "autoIncrement": "NO", + "defaultValue": null + }, + { + "name": "to_date", + "type": "DATE", + "size": 10, + "decimalDigits": null, + "comment": "", + "isPrimaryKey": false, + "nullable": "YES", + "autoIncrement": "NO", + "defaultValue": null + } + ], + "indexes": [ + { + "name": "PRIMARY", + "isUniqueKey": true, + "columnNames": [ + "emp_no", + "title", + "from_date" + ] + } + ], + "foreignKeys": [ + { + "fkName": "titles_ibfk_1", + "fkTableName": "titles", + "fkColumnName": "emp_no", + "pkName": "PRIMARY", + "pkTableName": "employees", + "pkColumnName": "emp_no", + "updateRule": "CASCADE", + "deleteRule": "CASCADE" + } + ], + "triggers": [] + } + ] +} \ No newline at end of file