Support table schema edit

This commit is contained in:
SwallowGG
2023-10-09 18:27:24 +08:00
parent 51452dbfd0
commit ab1cad3cbe
16 changed files with 626 additions and 7 deletions

View File

@ -268,6 +268,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
.columnTypes(MysqlColumnTypeEnum.getTypes())
.charsets(MysqlCharsetEnum.getCharsets())
.collations(MysqlCollationEnum.getCollations())
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
.build();
}

View File

@ -82,7 +82,7 @@ public class MysqlSqlBuilder implements SqlBuilder {
// append modify column
for (TableColumn tableColumn : newTable.getColumnList()) {
if (StringUtils.isNotBlank(tableColumn.getEditStatus())) {
if (StringUtils.isNotBlank(tableColumn.getEditStatus()) && StringUtils.isNotBlank(tableColumn.getColumnType())&& StringUtils.isNotBlank(tableColumn.getName())){
MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(tableColumn.getColumnType());
script.append("\t").append(typeEnum.buildModifyColumn(tableColumn)).append(",\n");
}

View File

@ -1,10 +1,14 @@
package ai.chat2db.plugin.mysql.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum MysqlIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
@ -30,9 +34,20 @@ public enum MysqlIndexTypeEnum {
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
MysqlIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
@ -108,4 +123,7 @@ public enum MysqlIndexTypeEnum {
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(MysqlIndexTypeEnum.values()).stream().map(MysqlIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}