support table edit

This commit is contained in:
SwallowGG
2023-09-25 17:47:16 +08:00
parent 21c415b196
commit aa550e354a
4 changed files with 38 additions and 11 deletions

View File

@ -18,14 +18,20 @@ public class MysqlSqlBuilder implements SqlBuilder {
// append column
for (TableColumn column : table.getColumnList()) {
if(StringUtils.isBlank(column.getName())|| StringUtils.isBlank(column.getColumnType())){
continue;
}
MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(column.getColumnType());
script.append("\t").append(typeEnum.buildCreateColumnSql(column)).append(",\n");
}
// append primary key and index
for (TableIndex tableIndex : table.getIndexList()) {
if(StringUtils.isBlank(tableIndex.getName())|| StringUtils.isBlank(tableIndex.getType())){
continue;
}
MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType());
script.append("\t").append("ADD ").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n");
script.append("\t").append("").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n");
}
script = new StringBuilder(script.substring(0, script.length() - 2));
@ -84,7 +90,7 @@ public class MysqlSqlBuilder implements SqlBuilder {
// append modify index
for (TableIndex tableIndex : newTable.getIndexList()) {
if (StringUtils.isNotBlank(tableIndex.getEditStatus())) {
if (StringUtils.isNotBlank(tableIndex.getEditStatus()) && StringUtils.isNotBlank(tableIndex.getType())) {
MysqlIndexTypeEnum mysqlIndexTypeEnum = MysqlIndexTypeEnum.getByType(tableIndex.getType());
script.append("\t").append(mysqlIndexTypeEnum.buildModifyIndex(tableIndex)).append(",\n");
}

View File

@ -9,13 +9,13 @@ public enum MysqlIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE KEY"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT KEY"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL KEY");
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
@ -72,7 +72,9 @@ public enum MysqlIndexTypeEnum {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
script.append("`").append(column.getColumnName()).append("`").append(",");
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`").append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
@ -104,6 +106,6 @@ public enum MysqlIndexTypeEnum {
if (MysqlIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP KEY `", tableIndex.getOldName());
return StringUtils.join("DROP INDEX `", tableIndex.getOldName());
}
}