mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-10-04 12:34:50 +08:00
fix: 字段类型转换
This commit is contained in:
parent
38c50fc7cd
commit
130b839c9d
1 changed files with 21 additions and 11 deletions
|
@ -438,27 +438,37 @@ public class Field2Schema extends SetUser {
|
||||||
meta.setString("displayType", toType.name());
|
meta.setString("displayType", toType.name());
|
||||||
Application.getCommonsService().update(meta, false);
|
Application.getCommonsService().update(meta, false);
|
||||||
|
|
||||||
Dialect dialect = Application.getPersistManagerFactory().getDialect();
|
// 类型生效
|
||||||
final Table table = new Table(field.getOwnEntity(), dialect);
|
DynamicMetadataContextHolder.setSkipLanguageRefresh();
|
||||||
StringBuilder ddl = new StringBuilder();
|
MetadataHelper.getMetadataFactory().refresh();
|
||||||
table.generateFieldDDL(field, ddl);
|
field = MetadataHelper.getField(field.getOwnEntity().getName(), field.getName());
|
||||||
|
|
||||||
String alterSql = String.format("alter table `%s` change column `%s` ",
|
|
||||||
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
|
|
||||||
alterSql += ddl.toString().trim();
|
|
||||||
|
|
||||||
|
String alterTypeSql = null;
|
||||||
try {
|
try {
|
||||||
Application.getSqlExecutor().executeBatch(new String[]{alterSql}, DDL_TIMEOUT);
|
Dialect dialect = Application.getPersistManagerFactory().getDialect();
|
||||||
|
final Table table = new Table(field.getOwnEntity(), dialect);
|
||||||
|
StringBuilder ddl = new StringBuilder();
|
||||||
|
table.generateFieldDDL(field, ddl);
|
||||||
|
|
||||||
|
alterTypeSql = String.format("alter table `%s` change column `%s` ",
|
||||||
|
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
|
||||||
|
alterTypeSql += ddl.toString().trim().replace(" ", "");
|
||||||
|
|
||||||
|
Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT);
|
||||||
|
log.info("Cast field type : {}", alterTypeSql);
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
// 还原
|
// 还原
|
||||||
meta.setString("displayType", EasyMetaFactory.getDisplayType(field).name());
|
meta.setString("displayType", EasyMetaFactory.getDisplayType(field).name());
|
||||||
Application.getCommonsService().update(meta, false);
|
Application.getCommonsService().update(meta, false);
|
||||||
|
|
||||||
log.error("DDL ERROR : \n" + alterSql, ex);
|
log.error("DDL ERROR : \n" + alterTypeSql, ex);
|
||||||
throw new MetadataModificationException(ThrowableUtils.getRootCause(ex).getLocalizedMessage());
|
throw new MetadataModificationException(ThrowableUtils.getRootCause(ex).getLocalizedMessage());
|
||||||
|
} finally {
|
||||||
|
MetadataHelper.getMetadataFactory().refresh();
|
||||||
|
DynamicMetadataContextHolder.isSkipLanguageRefresh(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataHelper.getMetadataFactory().refresh();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue