feat(issue-#155): rename plugin module to meta (#156)

* feat(issue-#155): rename  module plugin to meta

* feat: remove unused md file

* refactor: rename plugin module to meta

* fix: trigger document error

* fix: code checkstyle
This commit is contained in:
vran
2022-05-08 22:47:47 +08:00
committed by GitHub
parent f2c4de5bb1
commit bab82d43df
93 changed files with 201 additions and 182 deletions

7
meta/build.gradle Normal file
View File

@@ -0,0 +1,7 @@
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}"
}

View File

@@ -0,0 +1,50 @@
package com.databasir.core;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.meta.provider.MetaProviders;
import com.databasir.core.meta.provider.condition.Condition;
import com.databasir.core.render.Render;
import com.databasir.core.render.RenderConfig;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.util.Optional;
@RequiredArgsConstructor
@Getter
public class Databasir {
private final DatabasirConfig config;
public Optional<DatabaseMeta> get(Connection connection, String databaseName, String schemaName) {
Condition condition = Condition.builder()
.databaseName(databaseName)
.schemaName(schemaName)
.ignoreTableNameRegex(config.getIgnoreTableNameRegex())
.ignoreTableColumnNameRegex(config.getIgnoreTableColumnNameRegex())
.build();
return MetaProviders
.of(connection)
.select(connection, condition);
}
public void renderAsMarkdown(DatabaseMeta meta, OutputStream out) throws IOException {
renderAsMarkdown(new RenderConfig(), meta, out);
}
public void renderAsMarkdown(RenderConfig config, DatabaseMeta meta, OutputStream stream) throws IOException {
Render.markdownRender(config).rendering(meta, stream);
}
public static Databasir of() {
return of(new DatabasirConfig());
}
public static Databasir of(DatabasirConfig config) {
return new Databasir(config);
}
}

View File

@@ -0,0 +1,26 @@
package com.databasir.core;
import lombok.Getter;
import lombok.Setter;
import java.util.Collection;
import java.util.HashSet;
@Getter
@Setter
public class DatabasirConfig {
private Collection<String> ignoreTableNameRegex = new HashSet<>();
private Collection<String> ignoreTableColumnNameRegex = new HashSet<>();
public DatabasirConfig ignoreTable(String tableNameRegex) {
ignoreTableNameRegex.add(tableNameRegex);
return this;
}
public DatabasirConfig ignoreColumn(String columnNameRegex) {
ignoreTableColumnNameRegex.add(columnNameRegex);
return this;
}
}

View File

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

View File

@@ -0,0 +1,11 @@
package com.databasir.core.diff.data;
public interface Diff {
DiffType getDiffType();
Object getOriginal();
Object getCurrent();
}

View File

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

View File

@@ -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<FieldDiff> fields = new ArrayList<>();
}

View File

@@ -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<FieldDiff> fields = new ArrayList<>();
}

View File

@@ -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<ColumnMeta> {
@Override
public FieldDiff process(String fieldName, List<ColumnMeta> original, List<ColumnMeta> current) {
return diffTableField(original, current, fieldName, ColumnMeta::getName);
}
}

View File

@@ -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<FieldDiff> 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<FieldDiff> diffDatabaseFields(DatabaseMeta original, DatabaseMeta current) {
Class<DatabaseMeta> clazz = DatabaseMeta.class;
Field[] fields = clazz.getDeclaredFields();
List<FieldDiff> 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;
}
}

View File

@@ -0,0 +1,101 @@
package com.databasir.core.diff.processor;
import com.databasir.core.diff.data.DiffType;
import com.databasir.core.diff.data.FieldDiff;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
public interface DiffProcessor<T> {
Logger log = LoggerFactory.getLogger(DiffProcessor.class);
FieldDiff process(String fieldName, List<T> original, List<T> current);
default FieldDiff diffTableField(List<T> original,
List<T> current,
String fieldName,
Function<T, String> identity) {
Map<String, T> originalMap = toMap(original, identity);
Map<String, T> currentMap = toMap(current, identity);
List<FieldDiff> columnFieldDiffs = new ArrayList<>(32);
// removed
List<FieldDiff> removedFields = originalRemovedField(originalMap, currentMap);
columnFieldDiffs.addAll(removedFields);
// added
List<FieldDiff> addedFields = currentAddedField(originalMap, currentMap);
columnFieldDiffs.addAll(addedFields);
// modified
List<FieldDiff> modifiedFields = modifiedField(originalMap, currentMap);
columnFieldDiffs.addAll(modifiedFields);
return FieldDiff.builder()
.fieldName(fieldName)
.diffType(columnFieldDiffs.isEmpty() ? DiffType.NONE : DiffType.MODIFIED)
.fields(columnFieldDiffs)
.build();
}
default Map<String, T> toMap(List<T> content, Function<T, String> idMapping) {
return content
.stream()
.collect(Collectors.toMap(idMapping, Function.identity(), (a, b) -> {
log.warn("Duplicate key, origin = {}, current = {}", a, b);
return a;
}));
}
default List<FieldDiff> originalRemovedField(Map<String, T> originalMapById,
Map<String, T> 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<FieldDiff> currentAddedField(Map<String, T> originalMapById,
Map<String, T> 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<FieldDiff> modifiedField(Map<String, T> original,
Map<String, T> current) {
List<FieldDiff> 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;
}
}

View File

@@ -0,0 +1,18 @@
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<ForeignKeyMeta> {
@Override
public FieldDiff process(String fieldName, List<ForeignKeyMeta> original, List<ForeignKeyMeta> current) {
return diffTableField(
original,
current,
"foreignKeys",
fk -> fk.getFkTableName() + "." + fk.getFkColumnName() + "." + fk.getKeySeq());
}
}

View File

@@ -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<IndexMeta> {
@Override
public FieldDiff process(String fieldName, List<IndexMeta> original, List<IndexMeta> current) {
return diffTableField(original, current, fieldName, IndexMeta::getName);
}
}

View File

@@ -0,0 +1,158 @@
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<TableMeta> {
private final IndexDiffProcessor indexDiffProcessor = new IndexDiffProcessor();
private final ColumnDiffProcessor columnDiffProcessor = new ColumnDiffProcessor();
private final TriggerDiffProcessor triggerDiffProcessor = new TriggerDiffProcessor();
private final ForeignKeyDiffProcessor foreignKeyDiffProcessor = new ForeignKeyDiffProcessor();
private static final TableMeta EMPTY = new TableMeta();
@Override
public FieldDiff process(String fieldName, List<TableMeta> original, List<TableMeta> current) {
// diff tables field
Map<String, TableMeta> originalMap = toMap(original, TableMeta::getName);
Map<String, TableMeta> currentMap = toMap(current, TableMeta::getName);
List<FieldDiff> tables = new ArrayList<>();
List<TableMeta> added = added(originalMap, currentMap);
List<TableMeta> removed = removed(originalMap, currentMap);
// added
List<FieldDiff> addedFields = added.stream()
.map(table -> diffTableField(EMPTY, table))
.collect(Collectors.toList());
tables.addAll(addedFields);
// removed
List<FieldDiff> removedFields = removed.stream()
.map(table -> diffTableField(table, EMPTY))
.collect(Collectors.toList());
tables.addAll(removedFields);
// modified
List<FieldDiff> 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 List<TableMeta> added(Map<String, TableMeta> originalMap,
Map<String, TableMeta> currentMap) {
return currentMap.entrySet()
.stream()
.filter(entry -> !originalMap.containsKey(entry.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
}
private List<TableMeta> removed(Map<String, TableMeta> originalMap,
Map<String, TableMeta> currentMap) {
return originalMap.entrySet()
.stream()
.filter(entry -> !currentMap.containsKey(entry.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toList());
}
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<FieldDiff> otherFields = fields(original, current);
List<FieldDiff> fields = new ArrayList<>();
fields.add(columns);
fields.add(indexes);
fields.add(foreignKeys);
fields.add(triggers);
fields.addAll(otherFields);
DiffType diffType;
if (original == EMPTY) {
diffType = DiffType.ADDED;
} else if (current == EMPTY) {
diffType = DiffType.REMOVED;
} else {
diffType = DiffType.MODIFIED;
}
return FieldDiff.builder()
.diffType(diffType)
.fieldName(original == EMPTY ? current.getName() : original.getName())
.original(current == EMPTY ? original : null)
.current(original == EMPTY ? current : null)
.fields(fields)
.build();
}
private List<FieldDiff> fields(TableMeta original, TableMeta current) {
List<FieldDiff> fields = new ArrayList<>();
// ignore tables diff
Class<TableMeta> clazz = TableMeta.class;
List<String> 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;
}
}

View File

@@ -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<TriggerMeta> {
@Override
public FieldDiff process(String fieldName, List<TriggerMeta> original, List<TriggerMeta> current) {
return diffTableField(original, current, fieldName, TriggerMeta::getName);
}
}

View File

@@ -0,0 +1,36 @@
package com.databasir.core.meta.data;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ColumnMeta {
private String name;
private String comment;
private String type;
private Integer dataType;
/**
* if default value is empty string, will be converted to ''.
*/
private String defaultValue;
private Integer size;
private Integer decimalDigits;
private String nullable;
private String autoIncrement;
private Boolean isPrimaryKey;
}

View File

@@ -0,0 +1,50 @@
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 {
/**
* product_name
*/
private String productName;
/**
* product_version
*/
private String productVersion;
/**
* driver_name
*/
private String driverName;
/**
* driver_version
*/
private String driverVersion;
/**
* database_name
*/
private String databaseName;
/**
* schema_name
*/
private String schemaName;
@Builder.Default
private List<TableMeta> tables = Collections.emptyList();
}

View File

@@ -0,0 +1,43 @@
package com.databasir.core.meta.data;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ForeignKeyMeta {
private Integer keySeq;
/**
* may null
*/
private String pkName;
private String pkTableName;
private String pkColumnName;
/**
* may null
*/
private String fkName;
private String fkTableName;
private String fkColumnName;
/**
* NO_ACTION \ CASCADE \ SET_NULL \ SET_DEFAULT
*/
private String updateRule;
/**
* NO_ACTION \ CASCADE \ SET_NULL \ SET_DEFAULT
*/
private String deleteRule;
}

View File

@@ -0,0 +1,23 @@
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;
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class IndexMeta {
private String name;
@Builder.Default
private List<String> columnNames = Collections.emptyList();
private Boolean isUniqueKey;
}

View File

@@ -0,0 +1,34 @@
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;
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TableMeta {
private String name;
private String type;
private String comment;
@Builder.Default
private List<ColumnMeta> columns = Collections.emptyList();
@Builder.Default
private List<TriggerMeta> triggers = Collections.emptyList();
@Builder.Default
private List<IndexMeta> indexes = Collections.emptyList();
@Builder.Default
private List<ForeignKeyMeta> foreignKeys = Collections.emptyList();
}

View File

@@ -0,0 +1,32 @@
package com.databasir.core.meta.data;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* now: only support mysql, postgresql.
*/
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TriggerMeta {
private String name;
/**
* example: BEFORE, AFTER
*/
private String timing;
/**
* example: INSERT, UPDATE
*/
private String manipulation;
private String statement;
private String createAt;
}

View File

@@ -0,0 +1,13 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.ColumnMeta;
import com.databasir.core.meta.provider.condition.TableCondition;
import java.sql.Connection;
import java.util.List;
public interface ColumnMetaProvider {
List<ColumnMeta> selectColumns(Connection connection, TableCondition condition);
}

View File

@@ -0,0 +1,13 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.meta.provider.condition.Condition;
import java.sql.Connection;
import java.util.Optional;
public interface DatabaseMetaProvider {
Optional<DatabaseMeta> select(Connection connection, Condition condition);
}

View File

@@ -0,0 +1,13 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.ForeignKeyMeta;
import com.databasir.core.meta.provider.condition.TableCondition;
import java.sql.Connection;
import java.util.List;
public interface ForeignKeyMetaProvider {
List<ForeignKeyMeta> selectForeignKeys(Connection connection, TableCondition condition);
}

View File

@@ -0,0 +1,12 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.IndexMeta;
import com.databasir.core.meta.provider.condition.TableCondition;
import java.sql.Connection;
import java.util.List;
public interface IndexMetaProvider {
List<IndexMeta> selectIndexes(Connection connection, TableCondition condition);
}

View File

@@ -0,0 +1,60 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.provider.jdbc.*;
import com.databasir.core.meta.provider.mysql.MysqlTableTriggerMetaProvider;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@Slf4j
public class MetaProviders {
public static DatabaseMetaProvider jdbc() {
var columnMetaProvider = new JdbcColumnMetaProvider();
var foreignKeyMetaProvider = new JdbcForeignKeyMetaProvider();
var indexMetaProvider = new JdbcIndexMetaProvider();
var triggerMetaProvider = new JdbcTriggerMetaProvider();
var tableMetaProvider = new JdbcTableMetaProvider(
columnMetaProvider,
indexMetaProvider,
triggerMetaProvider,
foreignKeyMetaProvider
);
return new JdbcDatabaseMetaProvider(tableMetaProvider);
}
public static DatabaseMetaProvider of(Connection connection) {
String url;
try {
DatabaseMetaData metaData = connection.getMetaData();
url = metaData.getURL();
} catch (SQLException e) {
log.warn("failed to get connect url, {}, fallback to jdbc provider", e.getMessage());
return jdbc();
}
if (url.contains(":sqlserver:")) {
return jdbc();
}
if (url.contains(":mysql:")) {
return mysql();
}
return jdbc();
}
private static DatabaseMetaProvider mysql() {
var columnMetaProvider = new JdbcColumnMetaProvider();
var foreignKeyMetaProvider = new JdbcForeignKeyMetaProvider();
var indexMetaProvider = new JdbcIndexMetaProvider();
var triggerMetaProvider = new MysqlTableTriggerMetaProvider();
var tableMetaProvider = new JdbcTableMetaProvider(
columnMetaProvider,
indexMetaProvider,
triggerMetaProvider,
foreignKeyMetaProvider
);
return new JdbcDatabaseMetaProvider(tableMetaProvider);
}
}

View File

@@ -0,0 +1,75 @@
package com.databasir.core.meta.provider;
import java.util.Optional;
/**
* TODO use to extension repository
*/
public interface SqlProvider {
Default DEFAULT = new Default();
/**
* <p>
* generate sql to select database information, should return the follow columns
* </p>
*
* <table>
* <tr>
* <th> column name </th>
* <th> column type </th>
* <th> description </th>
* <th> nullable </th>
* </tr>
* <tr>
* <td> TABLE_CAT </td>
* <td> String </td>
* <td> catalog name </td>
* <td> NO </td>
* </tr>
* </table>
* <br>
*
*/
default Optional<String> databaseMetaSql(String databaseName) {
return Optional.empty();
}
/**
* generate sql to select table information, should return the follow columns
* <table>
* <tr>
* <th> column name </th>
* <th> column type </th>
* <th> description </th>
* <th> nullable </th>
* </tr>
* <tr>
* <td> TABLE_CAT </td>
* <td> String </td>
* <td> catalog name </td>
* <td> NO </td>
* </tr>
* </table>
*
*/
default Optional<String> tableMetaSql(String databaseName, String tableName) {
return Optional.empty();
}
default Optional<String> tableColumnMetaSql(String databaseName, String tableName) {
return Optional.empty();
}
default Optional<String> tableIndexMetaSql(String databaseName, String tableName) {
return Optional.empty();
}
default Optional<String> tableTriggerMetaSql(String databaseName, String tableName) {
return Optional.empty();
}
class Default implements SqlProvider {
}
}

View File

@@ -0,0 +1,13 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.TableMeta;
import com.databasir.core.meta.provider.condition.Condition;
import java.sql.Connection;
import java.util.List;
public interface TableMetaProvider {
List<TableMeta> selectTables(Connection connection, Condition condition);
}

View File

@@ -0,0 +1,13 @@
package com.databasir.core.meta.provider;
import com.databasir.core.meta.data.TriggerMeta;
import com.databasir.core.meta.provider.condition.TableCondition;
import java.sql.Connection;
import java.util.List;
public interface TriggerMetaProvider {
List<TriggerMeta> selectTriggers(Connection connection, TableCondition condition);
}

View File

@@ -0,0 +1,34 @@
package com.databasir.core.meta.provider.condition;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;
import java.util.Collection;
import java.util.Collections;
import java.util.regex.Pattern;
@SuperBuilder
@Getter
public class Condition {
@NonNull
private String databaseName;
private String schemaName;
@Builder.Default
private Collection<String> ignoreTableNameRegex = Collections.emptyList();
@Builder.Default
private Collection<String> ignoreTableColumnNameRegex = Collections.emptyList();
public boolean tableIsIgnored(String tableName) {
return ignoreTableNameRegex.stream().anyMatch(regex -> Pattern.matches(regex, tableName));
}
public boolean columnIsIgnored(String column) {
return ignoreTableColumnNameRegex.stream().anyMatch(regex -> Pattern.matches(regex, column));
}
}

View File

@@ -0,0 +1,24 @@
package com.databasir.core.meta.provider.condition;
import lombok.Getter;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;
@SuperBuilder
@Getter
public class TableCondition extends Condition {
@NonNull
private String tableName;
public static TableCondition of(Condition condition, String tableName) {
return TableCondition.builder()
.databaseName(condition.getDatabaseName())
.tableName(tableName)
.schemaName(condition.getSchemaName())
.ignoreTableNameRegex(condition.getIgnoreTableNameRegex())
.ignoreTableColumnNameRegex(condition.getIgnoreTableColumnNameRegex())
.build();
}
}

View File

@@ -0,0 +1,129 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.ColumnMeta;
import com.databasir.core.meta.provider.ColumnMetaProvider;
import com.databasir.core.meta.provider.condition.TableCondition;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@RequiredArgsConstructor
public class JdbcColumnMetaProvider implements ColumnMetaProvider {
@Override
public List<ColumnMeta> selectColumns(Connection connection, TableCondition tableCondition) {
try {
return doSelect(connection, tableCondition);
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
private List<ColumnMeta> doSelect(Connection connection, TableCondition tableCondition) throws SQLException {
List<ColumnMeta> columnDocs = new ArrayList<>();
String databaseName = tableCondition.getDatabaseName();
String tableName = tableCondition.getTableName();
List<String> primaryKeyColumns = selectPrimaryKeyColumns(connection.getMetaData(), tableCondition);
ResultSet columnsResult;
try {
columnsResult = connection.getMetaData()
.getColumns(databaseName, tableCondition.getSchemaName(), tableName, null);
} catch (SQLException e) {
log.warn("warn: ignore columns in " + databaseName + "." + tableName + ", error: " + e.getMessage());
return columnDocs;
}
try {
while (columnsResult.next()) {
String columnName = columnsResult.getString("COLUMN_NAME");
if (tableCondition.columnIsIgnored(columnName)) {
if (log.isWarnEnabled()) {
log.warn("ignore column: " + columnName);
}
} else {
String defaultValue = columnsResult.getString("COLUMN_DEF");
String isNullable = columnsResult.getString("IS_NULLABLE");
if (isNullable.trim().equals("")) {
isNullable = "UNKNOWN";
}
if (defaultValue != null && defaultValue.trim().equals("")) {
defaultValue = "'" + defaultValue + "'";
}
Integer decimalDigits;
if (columnsResult.getObject("DECIMAL_DIGITS") == null) {
decimalDigits = null;
} else {
decimalDigits = columnsResult.getInt("DECIMAL_DIGITS");
}
Integer columnSize = columnsResult.getInt("COLUMN_SIZE");
String columnType = columnsResult.getString("TYPE_NAME");
String columnComment = columnsResult.getString("REMARKS");
int dataType = columnsResult.getInt("DATA_TYPE");
String autoIncrement = retrieveAutoIncrement(columnsResult);
ColumnMeta columnMeta = ColumnMeta.builder()
.name(columnName)
.dataType(dataType)
.type(columnType)
.size(columnSize)
.decimalDigits(decimalDigits)
.nullable(isNullable)
.autoIncrement(autoIncrement)
.comment(columnComment)
.defaultValue(defaultValue)
.isPrimaryKey(primaryKeyColumns.contains(columnName))
.build();
columnDocs.add(columnMeta);
}
}
} finally {
columnsResult.close();
}
return columnDocs;
}
private String retrieveAutoIncrement(ResultSet columnsResult) {
try {
return retrieveAutoIncrement(columnsResult, "IS_AUTOINCREMENT");
} catch (SQLException e) {
log.warn("get is_autoincrement failed, fallback to is_auto_increment, error: " + e.getMessage());
try {
// hive jdbc driver doesn't support is_autoincrement, fallback to is_auto_increment
return retrieveAutoIncrement(columnsResult, "is_auto_increment");
} catch (SQLException ex) {
log.warn("get is_auto_increment failed, error: " + ex.getMessage());
return "UNKNOWN";
}
}
}
private String retrieveAutoIncrement(ResultSet columnsResult, String columnName) throws SQLException {
String isAutoIncrement = columnsResult.getString(columnName);
if (isAutoIncrement.trim().equals("")) {
return "UNKNOWN";
}
return isAutoIncrement;
}
private List<String> selectPrimaryKeyColumns(DatabaseMetaData meta,
TableCondition tableCondition) throws SQLException {
ResultSet result = meta.getPrimaryKeys(tableCondition.getDatabaseName(),
tableCondition.getSchemaName(), tableCondition.getTableName());
try {
List<String> columns = new ArrayList<>();
while (result.next()) {
String columnName = result.getString("COLUMN_NAME");
columns.add(columnName);
}
return columns;
} finally {
result.close();
}
}
}

View File

@@ -0,0 +1,64 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.meta.data.TableMeta;
import com.databasir.core.meta.provider.DatabaseMetaProvider;
import com.databasir.core.meta.provider.TableMetaProvider;
import com.databasir.core.meta.provider.condition.Condition;
import lombok.RequiredArgsConstructor;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@RequiredArgsConstructor
public class JdbcDatabaseMetaProvider implements DatabaseMetaProvider {
private final TableMetaProvider tableMetaProvider;
@Override
public Optional<DatabaseMeta> select(Connection connection, Condition condition) {
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet catalogs = metaData.getCatalogs();
while (catalogs.next()) {
String catalogName = catalogs.getString("TABLE_CAT");
if (Objects.equals(condition.getDatabaseName(), catalogName)) {
List<TableMeta> tableDocs = tableMetaProvider.selectTables(connection, condition);
DatabaseMeta meta = DatabaseMeta.builder()
.productName(metaData.getDatabaseProductName())
.productVersion(metaData.getDatabaseProductVersion())
.databaseName(catalogName)
.schemaName(condition.getSchemaName())
.tables(tableDocs)
.build();
return Optional.of(meta);
}
}
ResultSet schemas = metaData.getSchemas();
while (schemas.next()) {
String schemaName = schemas.getString("TABLE_SCHEM");
if (Objects.equals(condition.getSchemaName(), schemaName)) {
List<TableMeta> tableDocs = tableMetaProvider.selectTables(connection, condition);
DatabaseMeta meta = DatabaseMeta.builder()
.productName(metaData.getDatabaseProductName())
.productVersion(metaData.getDatabaseProductVersion())
.databaseName(condition.getDatabaseName())
.schemaName(condition.getSchemaName())
.tables(tableDocs)
.build();
return Optional.of(meta);
}
}
return Optional.empty();
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
}

View File

@@ -0,0 +1,92 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.ForeignKeyMeta;
import com.databasir.core.meta.provider.ForeignKeyMetaProvider;
import com.databasir.core.meta.provider.condition.TableCondition;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class JdbcForeignKeyMetaProvider implements ForeignKeyMetaProvider {
@Override
public List<ForeignKeyMeta> selectForeignKeys(Connection connection, TableCondition condition) {
String databaseName = condition.getDatabaseName();
String schemaName = condition.getSchemaName();
String tableName = condition.getTableName();
List<ForeignKeyMeta> foreignKeys = new ArrayList<>();
ResultSet keyResult = null;
try {
keyResult = connection.getMetaData().getImportedKeys(databaseName, schemaName, tableName);
while (keyResult.next()) {
String fkTableName = keyResult.getString("FKTABLE_NAME");
String fkColumnName = keyResult.getString("FKCOLUMN_NAME");
String fkName = keyResult.getString("FK_NAME");
String pkTableName = keyResult.getString("PKTABLE_NAME");
String pkColumnName = keyResult.getString("PKCOLUMN_NAME");
String pkName = keyResult.getString("PK_NAME");
int updateRule = keyResult.getInt("UPDATE_RULE");
int keySeq = keyResult.getInt("KEY_SEQ");
int deleteRule = keyResult.getInt("DELETE_RULE");
ForeignKeyMeta meta = ForeignKeyMeta.builder()
.keySeq(keySeq)
.fkTableName(fkTableName)
.fkColumnName(fkColumnName)
.fkName(fkName)
.pkTableName(pkTableName)
.pkColumnName(pkColumnName)
.pkName(pkName)
.updateRule(updateRuleConvert(updateRule))
.deleteRule(deleteRuleConvert(deleteRule))
.build();
foreignKeys.add(meta);
}
} catch (SQLException e) {
log.warn("warn: ignore foreign keys in " + databaseName + "." + tableName + ", " + e.getMessage());
} finally {
try {
if (keyResult != null) {
keyResult.close();
}
} catch (SQLException e) {
log.warn("warn: close key result error " + databaseName + "." + tableName + ", " + e.getMessage());
}
}
return foreignKeys;
}
private String updateRuleConvert(int updateRule) {
return doMapping(updateRule, "update");
}
private String deleteRuleConvert(int deleteRule) {
return doMapping(deleteRule, "delete");
}
private String doMapping(int rule, String type) {
if (rule == DatabaseMetaData.importedKeyCascade) {
return "CASCADE";
}
if (rule == DatabaseMetaData.importedKeyRestrict) {
return "CASCADE";
}
if (rule == DatabaseMetaData.importedKeyNoAction) {
return "RESTRICT";
}
if (rule == DatabaseMetaData.importedKeySetNull) {
return "SET_NULL";
}
if (rule == DatabaseMetaData.importedKeySetDefault) {
return "SET_DEFAULT";
}
log.warn("can not map foreign key " + type + " rule = " + rule);
return "";
}
}

View File

@@ -0,0 +1,63 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.IndexMeta;
import com.databasir.core.meta.provider.IndexMetaProvider;
import com.databasir.core.meta.provider.condition.TableCondition;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@Slf4j
public class JdbcIndexMetaProvider implements IndexMetaProvider {
@Override
public List<IndexMeta> selectIndexes(Connection connection, TableCondition condition) {
try {
return doCreateIndexDocs(connection, condition);
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
private List<IndexMeta> doCreateIndexDocs(Connection connection, TableCondition condition)
throws SQLException {
String databaseName = condition.getDatabaseName();
String tableName = condition.getTableName();
List<IndexMeta> indexMetas = new ArrayList<>();
ResultSet indexResults;
try {
indexResults = connection.getMetaData()
.getIndexInfo(databaseName, condition.getSchemaName(), tableName, false, false);
} catch (SQLException e) {
log.warn("warn: ignore " + databaseName + "." + tableName + ", error=" + e.getMessage());
return indexMetas;
}
Map<String, IndexMeta> pojoGroupByName = new HashMap<>();
try {
while (indexResults.next()) {
Boolean nonUnique = indexResults.getBoolean("NON_UNIQUE");
String indexName = indexResults.getString("INDEX_NAME");
String columnName = indexResults.getString("COLUMN_NAME");
if (pojoGroupByName.containsKey(indexName)) {
pojoGroupByName.get(indexName).getColumnNames().add(columnName);
} else {
List<String> columns = new ArrayList<>();
columns.add(columnName);
IndexMeta indexMeta = IndexMeta.builder()
.name(indexName)
.columnNames(columns)
.isUniqueKey(Objects.equals(nonUnique, false))
.build();
pojoGroupByName.put(indexName, indexMeta);
}
}
} finally {
indexResults.close();
}
return new ArrayList<>(pojoGroupByName.values());
}
}

View File

@@ -0,0 +1,80 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.ColumnMeta;
import com.databasir.core.meta.data.TableMeta;
import com.databasir.core.meta.provider.*;
import com.databasir.core.meta.provider.condition.Condition;
import com.databasir.core.meta.provider.condition.TableCondition;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
@Slf4j
public class JdbcTableMetaProvider implements TableMetaProvider {
private final ColumnMetaProvider columnMetaProvider;
private final IndexMetaProvider indexMetaProvider;
private final TriggerMetaProvider triggerMetaProvider;
private final ForeignKeyMetaProvider foreignKeyMetaProvider;
@Override
public List<TableMeta> selectTables(Connection connection, Condition condition) {
try {
return doSelect(connection, condition);
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
private List<TableMeta> doSelect(Connection connection, Condition condition) throws SQLException {
List<TableMeta> tableMetas = new ArrayList<>();
String databaseName = condition.getDatabaseName();
ResultSet tablesResult = connection.getMetaData()
.getTables(databaseName, condition.getSchemaName(), null, new String[]{"TABLE"});
try {
while (tablesResult.next()) {
String tableName = tablesResult.getString("TABLE_NAME");
if (condition.tableIsIgnored(tableName)) {
if (log.isWarnEnabled()) {
log.warn("ignored table: " + databaseName + "." + tableName);
}
} else {
String tableType = tablesResult.getString("TABLE_TYPE");
String tableComment = tablesResult.getString("REMARKS");
TableCondition tableCondition = TableCondition.of(condition, tableName);
List<ColumnMeta> columns = columnMetaProvider.selectColumns(connection, tableCondition);
if (columns.isEmpty()) {
if (log.isWarnEnabled()) {
log.warn("ignored table: " + databaseName + "." + tableName
+ ", caused by get empty columns");
}
continue;
}
TableMeta tableMeta = TableMeta.builder()
.name(tableName)
.type(tableType)
.comment(tableComment)
.columns(columns)
.foreignKeys(foreignKeyMetaProvider.selectForeignKeys(connection, tableCondition))
.indexes(indexMetaProvider.selectIndexes(connection, tableCondition))
.triggers(triggerMetaProvider.selectTriggers(connection, tableCondition))
.build();
tableMetas.add(tableMeta);
}
}
} finally {
tablesResult.close();
}
return tableMetas;
}
}

View File

@@ -0,0 +1,18 @@
package com.databasir.core.meta.provider.jdbc;
import com.databasir.core.meta.data.TriggerMeta;
import com.databasir.core.meta.provider.TriggerMetaProvider;
import com.databasir.core.meta.provider.condition.TableCondition;
import java.sql.Connection;
import java.util.Collections;
import java.util.List;
public class JdbcTriggerMetaProvider implements TriggerMetaProvider {
@Override
public List<TriggerMeta> selectTriggers(Connection connection, TableCondition condition) {
// note: jdbc not support get triggers
return Collections.emptyList();
}
}

View File

@@ -0,0 +1,69 @@
package com.databasir.core.meta.provider.mysql;
import com.databasir.core.meta.data.TriggerMeta;
import com.databasir.core.meta.provider.TriggerMetaProvider;
import com.databasir.core.meta.provider.condition.TableCondition;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Slf4j
public class MysqlTableTriggerMetaProvider implements TriggerMetaProvider {
@Override
public List<TriggerMeta> selectTriggers(Connection connection, TableCondition condition) {
String sql = "SELECT TRIGGER_CATALOG,\n"
+ " TRIGGER_SCHEMA,\n"
+ " TRIGGER_NAME,\n"
+ " EVENT_MANIPULATION,\n"
+ " EVENT_OBJECT_CATALOG,\n"
+ " EVENT_OBJECT_SCHEMA,\n"
+ " EVENT_OBJECT_TABLE,\n"
+ " ACTION_ORDER,\n"
+ " ACTION_CONDITION,\n"
+ " ACTION_STATEMENT,\n"
+ " ACTION_ORIENTATION,\n"
+ " ACTION_TIMING,\n"
+ " ACTION_REFERENCE_OLD_TABLE,\n"
+ " ACTION_REFERENCE_NEW_TABLE,\n"
+ " ACTION_REFERENCE_OLD_ROW,\n"
+ " ACTION_REFERENCE_NEW_ROW,\n"
+ " CREATED,\n"
+ " SQL_MODE,\n"
+ " DEFINER\n "
+ "FROM information_schema.TRIGGERS WHERE EVENT_OBJECT_SCHEMA = ? AND EVENT_OBJECT_TABLE = ?";
try {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setObject(1, condition.getDatabaseName());
preparedStatement.setObject(2, condition.getTableName());
ResultSet results = preparedStatement.executeQuery();
List<TriggerMeta> triggers = new ArrayList<>();
while (results.next()) {
String name = results.getString("TRIGGER_NAME");
String statement = results.getString("ACTION_STATEMENT");
String timing = results.getString("ACTION_TIMING");
String manipulation = results.getString("EVENT_MANIPULATION");
String created = results.getString("CREATED");
TriggerMeta meta = TriggerMeta.builder()
.name(name)
.manipulation(manipulation)
.timing(timing)
.statement(statement)
.createAt(created)
.build();
triggers.add(meta);
}
return triggers;
} catch (SQLException e) {
log.warn("create trigger doc failed", e);
return Collections.emptyList();
}
}
}

View File

@@ -0,0 +1,17 @@
package com.databasir.core.render;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.render.markdown.MarkdownTemplateRender;
import java.io.IOException;
import java.io.OutputStream;
public interface Render {
void rendering(DatabaseMeta meta, OutputStream outputStream) throws IOException;
static Render markdownRender(RenderConfig configuration) {
return new MarkdownTemplateRender(configuration);
}
}

View File

@@ -0,0 +1,65 @@
package com.databasir.core.render;
import com.databasir.core.meta.data.ColumnMeta;
import com.databasir.core.meta.data.IndexMeta;
import com.databasir.core.meta.data.TriggerMeta;
import lombok.Data;
import java.util.LinkedHashMap;
import java.util.function.Function;
@Data
public class RenderConfig {
private Boolean renderTables = true;
private Boolean renderColumns = true;
private Boolean renderIndexes = true;
private Boolean renderTriggers = true;
private LinkedHashMap<String, Function<ColumnMeta, String>> columnTitleAndValueMapping =
columnTitleAndValueMapping();
private LinkedHashMap<String, Function<IndexMeta, String>> indexTitleAndValueMapping =
indexTitleAndValueMapping();
private LinkedHashMap<String, Function<TriggerMeta, String>> triggerTitleAndValueMapping =
triggerTitleAndValueMapping();
protected LinkedHashMap<String, Function<ColumnMeta, String>> columnTitleAndValueMapping() {
LinkedHashMap<String, Function<ColumnMeta, String>> mapping = new LinkedHashMap<>();
mapping.put("Name", ColumnMeta::getName);
mapping.put("Type", column -> {
String type;
if (column.getDecimalDigits() == null || column.getDecimalDigits().equals(0)) {
type = column.getType()
+ "(" + column.getSize().toString() + ")";
} else {
type = column.getType()
+ "(" + column.getSize().toString() + ", " + column.getDecimalDigits().toString() + ")";
}
return type;
});
return mapping;
}
protected LinkedHashMap<String, Function<IndexMeta, String>> indexTitleAndValueMapping() {
LinkedHashMap<String, Function<IndexMeta, String>> mapping = new LinkedHashMap<>();
mapping.put("Name", IndexMeta::getName);
mapping.put("IsUnique", index -> index.getIsUniqueKey() ? "YES" : "");
mapping.put("Columns", index -> String.join(", ", index.getColumnNames()));
return mapping;
}
protected LinkedHashMap<String, Function<TriggerMeta, String>> triggerTitleAndValueMapping() {
LinkedHashMap<String, Function<TriggerMeta, String>> mapping = new LinkedHashMap<>();
mapping.put("Name", TriggerMeta::getName);
mapping.put("Timing", trigger -> trigger.getTiming() + " " + trigger.getManipulation());
mapping.put("Statement", trigger -> trigger.getStatement().replace("\n", " ")
.replace("\r", " "));
mapping.put("Create At", TriggerMeta::getCreateAt);
return mapping;
}
}

View File

@@ -0,0 +1,108 @@
package com.databasir.core.render.markdown;
import java.util.List;
public class MarkdownBuilder {
private static final String LINE = "\n";
private static final String DOUBLE_LINE = LINE + LINE;
private StringBuilder builder = new StringBuilder(1024);
private MarkdownBuilder() {
}
public static MarkdownBuilder builder() {
return new MarkdownBuilder();
}
public MarkdownBuilder primaryTitle(String title) {
builder.append("# ").append(title).append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder secondTitle(String title) {
builder.append("## ").append(title).append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder thirdTitle(String title) {
builder.append("### ").append(title).append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder text(String text) {
builder.append(text).append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder table(List<String> titles, List<List<String>> rows) {
if (titles == null || titles.isEmpty()) {
throw new IllegalArgumentException("titles must not be null or empty");
}
// build titles
builder.append("| ");
for (String title : titles) {
builder.append(title).append(" | ");
}
builder.append(LINE);
// build separators
builder.append("| ");
for (String title : titles) {
builder.append("------").append(" | ");
}
builder.append(LINE);
// build rows
for (List<String> row : rows) {
builder.append("| ");
for (String column : row) {
builder.append(column).append(" | ");
}
builder.append(LINE);
}
builder.append(LINE);
return this;
}
public MarkdownBuilder orderedList(List<String> list) {
for (int i = 0; i < list.size(); i++) {
builder.append(i + 1).append(". ").append(list.get(i)).append(LINE);
}
builder.append(LINE);
return this;
}
public MarkdownBuilder unorderedList(List<String> list) {
for (String item : list) {
builder.append("- ").append(item).append(LINE);
}
builder.append(LINE);
return this;
}
public MarkdownBuilder blockquotes(String content) {
builder.append("> ").append(content).append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder code(String languageType, String statement) {
builder.append("```").append(languageType).append(LINE)
.append(statement)
.append("```")
.append(DOUBLE_LINE);
return this;
}
public MarkdownBuilder link(String text, String link) {
builder.append("[").append(text).append("]")
.append("(").append(link).append(")");
return this;
}
public String build() {
return builder.toString();
}
}

View File

@@ -0,0 +1,114 @@
package com.databasir.core.render.markdown;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.meta.data.TableMeta;
import com.databasir.core.render.Render;
import com.databasir.core.render.RenderConfig;
import lombok.Getter;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class MarkdownRender implements Render {
@Getter
private final RenderConfig config;
protected MarkdownRender(RenderConfig config) {
this.config = config;
}
public static MarkdownRender of(RenderConfig config) {
return new MarkdownRender(config);
}
@Override
public void rendering(DatabaseMeta meta,
OutputStream outputStream) throws IOException {
MarkdownBuilder contentBuilder = MarkdownBuilder.builder();
contentBuilder.primaryTitle(meta.getDatabaseName());
if (config.getRenderTables()) {
for (TableMeta table : meta.getTables()) {
buildTableName(contentBuilder, table);
if (config.getRenderColumns()) {
buildColumns(contentBuilder, table);
}
if (config.getRenderIndexes()) {
buildIndexes(contentBuilder, table);
}
if (config.getRenderTriggers()) {
buildTriggers(contentBuilder, table);
}
}
}
outputStream.write(contentBuilder.build().getBytes(StandardCharsets.UTF_8));
}
private void buildTableName(MarkdownBuilder contentBuilder, TableMeta table) {
String tableName;
if (table.getComment().isEmpty()) {
tableName = table.getName();
} else {
tableName = table.getName() + "(" + table.getComment() + ")";
}
contentBuilder.secondTitle(tableName);
}
private void buildColumns(MarkdownBuilder contentBuilder, TableMeta table) {
contentBuilder.unorderedList(Collections.singletonList("columns"));
List<List<String>> allColumnRows = table.getColumns()
.stream()
.map(column -> config.getColumnTitleAndValueMapping()
.values()
.stream()
.map(mapping -> mapping.apply(column))
.collect(Collectors.toList()))
.collect(Collectors.toList());
contentBuilder.table(tableTitles(), allColumnRows);
}
private void buildIndexes(MarkdownBuilder contentBuilder, TableMeta table) {
contentBuilder.unorderedList(Collections.singletonList("indexes"));
List<List<String>> allIndexRows = table.getIndexes().stream()
.map(index -> config.getIndexTitleAndValueMapping()
.values()
.stream()
.map(mapping -> mapping.apply(index))
.collect(Collectors.toList()))
.collect(Collectors.toList());
contentBuilder.table(indexTitles(), allIndexRows);
}
private void buildTriggers(MarkdownBuilder contentBuilder, TableMeta table) {
if (table.getTriggers() == null || table.getTriggers().isEmpty()) {
return;
}
contentBuilder.unorderedList(Collections.singletonList("triggers"));
List<List<String>> allRows = table.getTriggers().stream()
.map(trigger -> config.getTriggerTitleAndValueMapping()
.values()
.stream()
.map(mapping -> mapping.apply(trigger))
.collect(Collectors.toList()))
.collect(Collectors.toList());
contentBuilder.table(triggerTitles(), allRows);
}
private List<String> tableTitles() {
return new ArrayList<>(config.getColumnTitleAndValueMapping().keySet());
}
private List<String> indexTitles() {
return new ArrayList<>(config.getIndexTitleAndValueMapping().keySet());
}
private List<String> triggerTitles() {
return new ArrayList<>(config.getTriggerTitleAndValueMapping().keySet());
}
}

View File

@@ -0,0 +1,57 @@
package com.databasir.core.render.markdown;
import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.render.Render;
import com.databasir.core.render.RenderConfig;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
/**
* use freemarker template to render markdown
*/
@RequiredArgsConstructor
public class MarkdownTemplateRender implements Render {
private final RenderConfig renderConfig;
private String templatePath = "template/render/markdown/markdown.ftlh";
public MarkdownTemplateRender(RenderConfig config, String templatePath) {
this(config);
this.templatePath = templatePath;
}
@Override
public void rendering(DatabaseMeta meta, OutputStream outputStream) throws IOException {
doRendering(meta, outputStream);
}
public void doRendering(DatabaseMeta meta, OutputStream outputStream) throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_29);
cfg.setClassForTemplateLoading(getClass(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
cfg.setWrapUncheckedExceptions(true);
cfg.setFallbackOnNullLoopVariable(false);
Map<String, Object> root = new HashMap<>();
root.put("meta", meta);
root.put("config", renderConfig);
Template template = cfg.getTemplate(templatePath);
try {
template.process(root, new OutputStreamWriter(outputStream));
} catch (TemplateException e) {
throw new IllegalStateException(e);
}
}
}

View File

@@ -0,0 +1,49 @@
# ${meta.databaseName}
| | |
| --------------- | ---- |
| Database name | |
| Product name | |
| Product version | |
## Overview
| | name | type | comment |
| ---- | --------------- | ------ | ------ |
<#list meta.tables as table>
| ${table_index+1} | [${table.name}](#${table.name}) | ${table.type} | ${table.comment!'N/A'} |
</#list>
<#if config.renderTables>
<#list meta.tables as table>
## ${table.name}
<#if config.renderColumns>
### Columns
| | name | type | primary Key | nullable | auto increment| default | comment |
| --- | ---- | ---- | ----------- | -------- | ------------- | ------- | ------- |
<#list table.columns as column>
| ${column_index+1} | ${column.name} | ${column.type} | ${column.isPrimaryKey?then('YES','NO')} | ${column.nullable } | ${column.autoIncrement} | ${column.defaultValue!'NULL'} | ${column.comment!''} |
</#list>
</#if>
<#if config.renderIndexes>
### Indexes
| | name | unique | columns |
| --- | ---- | ------ | ------- |
<#list table.indexes as index>
| ${index_index+1} | ${index.name} | ${index.isUniqueKey?then('YES', 'NO')} | ${index.columnNames?join(', ')} |
</#list>
</#if>
<#if config.renderTriggers>
### Triggers
| | name | timing | statement | created |
| --- | ---- | ------ | --------- | ------- |
<#list table.triggers as trigger>
| ${trigger_index} | ${trigger.name} | ${trigger.timing + " " + trigger.manipulation } | ${trigger.statement?replace("\n", "<br>")?replace("\r", " ")} | ${trigger.createAt} |
</#list>
</#if>
</#list>
</#if>

View File

@@ -0,0 +1,597 @@
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<String, FieldDiff> 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<String, FieldDiff> tableFieldMap = tableField.getFields()
.stream()
.collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity()));
Map<String, TableMeta> 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<String, FieldDiff> tableFieldMap = tableField.getFields()
.stream()
.collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity()));
Map<String, TableMeta> 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());
});
}
/**
* modify three table: departments, dept_emp
* - dept_manager: add comment, change table type
* - departments: add comment
* - dept_emp: add comment
*/
@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());
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<String, FieldDiff> tableFieldMap = tableField.getFields()
.stream()
.collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity()));
Map<String, TableMeta> originalTableMap = original.getTables()
.stream()
.collect(Collectors.toMap(TableMeta::getName, Function.identity()));
Map<String, TableMeta> currentTableMap = current.getTables()
.stream()
.collect(Collectors.toMap(TableMeta::getName, Function.identity()));
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
* <p>
* department:
* - add column [deleted], [dept_code]
* - add index [dept_deleted]
* - add triggers [before_insert]
* - add foreignKeys [dept_emp_ibfk_1]
* </p>
*/
@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<String, FieldDiff> 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<String, FieldDiff> 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();
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);
}
}
});
}
/**
* departments
* column: dept_no add comment
* column: dept_name add comment
* indexes: dept_name change unique=false
* <p>
* 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
* </p>
*/
@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<String, FieldDiff> tableFieldMap = tablesField.getFields()
.stream()
.collect(Collectors.toMap(FieldDiff::getFieldName, Function.identity()));
Map<String, TableMeta> originalTaleMap = original.getTables()
.stream()
.collect(Collectors.toMap(TableMeta::getName, Function.identity()));
Map<String, TableMeta> currentTableMap = current.getTables()
.stream()
.collect(Collectors.toMap(TableMeta::getName, Function.identity()));
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);
}
}
}

View File

@@ -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": []
}
]
}

View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}

View File

@@ -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": []
}
]
}