Skip to content

Commit

Permalink
fixs datetime40
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Dec 28, 2024
1 parent 31b58e5 commit ab189fc
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 159 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from e28024 to c71189
23 changes: 22 additions & 1 deletion src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public boolean castType(Field field, DisplayType toType, boolean force) {

alterTypeSql = String.format("alter table `%s` change column `%s` ",
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
alterTypeSql += ddl.toString().trim().replace(" ", " ");
alterTypeSql += ddl.toString().trim().replaceAll("\\s+", " ");

Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT);
log.info("Cast field type : {}", alterTypeSql);
Expand All @@ -519,4 +519,25 @@ public boolean castType(Field field, DisplayType toType, boolean force) {

return true;
}

/**
* @param field
* @return
*/
public boolean fixsDatetime40(Field field) {
if (field.getType() != FieldType.TIMESTAMP) return false;

Dialect dialect = Application.getPersistManagerFactory().getDialect();
final Table table = new Table40(field.getOwnEntity(), dialect);
StringBuilder ddl = new StringBuilder();
table.generateFieldDDL(field, ddl);

String alterTypeSql = String.format("alter table `%s` change column `%s` ",
field.getOwnEntity().getPhysicalName(), field.getPhysicalName());
alterTypeSql += ddl.toString().trim().replaceAll("\\s+", " ");

Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT);
log.info("Fixs datetime field : {}", alterTypeSql);
return true;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/rebuild/core/metadata/impl/Table40.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import cn.devezhao.persist4j.dialect.Dialect;
import cn.devezhao.persist4j.util.support.Table;

import java.util.List;

/**
* Fixs timestamp to datetime
*
Expand All @@ -24,6 +26,10 @@ public Table40(Entity entity, Dialect dialect) {
super(entity, dialect);
}

public Table40(Entity entity, Dialect dialect, List<?> indexList) {
super(entity, dialect, indexList);
}

@Override
public void generateFieldDDL(Field field, StringBuilder into, boolean allowZeroDate) {
StringBuilder tmp = new StringBuilder();
Expand Down
185 changes: 93 additions & 92 deletions src/main/resources/scripts/db-init.sql

Large diffs are not rendered by default.

124 changes: 62 additions & 62 deletions src/main/resources/scripts/db-upgrade.sql

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/main/resources/web/assets/js/metadata/field-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@ class FieldTypeCast extends RbFormHandler {
<button className="btn btn-link" type="button" onClick={() => this.hide()}>
{$L('取消')}
</button>
<button className="btn btn-warning bosskey-show " type="button" onClick={() => this.post('datetime40')}>
Repair
</button>
</div>
</div>
</div>
Expand All @@ -880,8 +883,8 @@ class FieldTypeCast extends RbFormHandler {
})
}

post() {
const toType = $(this._$toType).val()
post(fixsType) {
const toType = fixsType || $(this._$toType).val()
if (!toType) return RbHighbar.create($L('不可转换'))

const $btn = $(this._$btns).find('.btn').button('loading')
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/rebuild/support/SchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cn.devezhao.persist4j.metadata.impl.ConfigurationMetadataFactory;
import cn.devezhao.persist4j.util.support.Table;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.impl.Table40;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.dom4j.Element;
Expand Down Expand Up @@ -68,7 +69,7 @@ static void generate() {
static void generate(int entityCode) {
Entity entity = metadataFactory.getEntity(entityCode);
Element root = ((ConfigurationMetadataFactory) metadataFactory).getConfigDocument().getRootElement();
Table table = new Table(
Table table = new Table40(
entity,
dialect,
root.selectSingleNode("//entity[@name='" + entity.getName() + "']").selectNodes("index"));
Expand Down

0 comments on commit ab189fc

Please sign in to comment.