mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 02:32:33 +08:00
Support table schema edit
This commit is contained in:
@ -268,6 +268,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
.columnTypes(MysqlColumnTypeEnum.getTypes())
|
||||
.charsets(MysqlCharsetEnum.getCharsets())
|
||||
.collations(MysqlCollationEnum.getCollations())
|
||||
.indexTypes(MysqlIndexTypeEnum.getIndexTypes())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user