mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-20 19:18:17 +00:00
mysql 转 Postgresql 增加默认值
This commit is contained in:
@@ -31,6 +31,7 @@ public class ColumnDescription {
|
||||
private String remarks;
|
||||
private boolean signed = false;
|
||||
private ProductTypeEnum productType;
|
||||
private String defaultValue;
|
||||
|
||||
public String getFieldName() {
|
||||
if (null != this.fieldName) {
|
||||
@@ -144,6 +145,14 @@ public class ColumnDescription {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public ColumnDescription copy() {
|
||||
ColumnDescription description = new ColumnDescription();
|
||||
description.setFieldName(fieldName);
|
||||
@@ -159,6 +168,7 @@ public class ColumnDescription {
|
||||
description.setRemarks(remarks);
|
||||
description.setSigned(signed);
|
||||
description.setProductType(productType);
|
||||
description.setDefaultValue(defaultValue);
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@@ -94,6 +94,7 @@ public class ColumnMetaData {
|
||||
protected int precision;
|
||||
protected int type;
|
||||
protected String remarks;
|
||||
protected String defaultValue;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
@@ -144,6 +145,18 @@ public class ColumnMetaData {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public boolean isHaveDefault() {
|
||||
return defaultValue != null && !defaultValue.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the value is a String.
|
||||
*
|
||||
@@ -471,6 +484,7 @@ public class ColumnMetaData {
|
||||
this.precision = precision;
|
||||
this.type = valtype;
|
||||
this.remarks = desc.getRemarks();
|
||||
this.defaultValue = desc.getDefaultValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public class TargetDataSourceProperties {
|
||||
private CaseConvertEnum columnNameCase = CaseConvertEnum.NONE;
|
||||
private Boolean targetDrop = Boolean.TRUE;
|
||||
private Boolean onlyCreate = Boolean.FALSE;
|
||||
private Boolean createTableAutoIncrement = Boolean.FALSE;
|
||||
private Boolean createTableAutoIncrement = Boolean.TRUE;
|
||||
private Boolean writerEngineInsert = Boolean.FALSE;
|
||||
private Boolean changeDataSync = Boolean.FALSE;
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import com.gitee.dbswitch.schema.TableDescription;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
@@ -133,9 +134,12 @@ public class MysqlMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
while (columns.next()) {
|
||||
String columnName = columns.getString("COLUMN_NAME");
|
||||
String remarks = columns.getString("REMARKS");
|
||||
String columnDefault = columns.getString("COLUMN_DEF");
|
||||
for (ColumnDescription cd : ret) {
|
||||
if (columnName.equals(cd.getFieldName())) {
|
||||
cd.setRemarks(remarks);
|
||||
// 补充默认值信息
|
||||
cd.setDefaultValue(columnDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -155,6 +155,14 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BOOLEAN:
|
||||
retval += "BOOLEAN";
|
||||
if (v.isHaveDefault()) {
|
||||
boolean b = Boolean.getBoolean(v.getDefaultValue());
|
||||
if (b) {
|
||||
retval += " DEFAULT true";
|
||||
} else {
|
||||
retval += " DEFAULT false";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_NUMBER:
|
||||
case ColumnMetaData.TYPE_INTEGER:
|
||||
@@ -189,6 +197,9 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
} else {
|
||||
retval += "DOUBLE PRECISION";
|
||||
}
|
||||
if (v.isHaveDefault()) {
|
||||
retval += " DEFAULT " + Integer.valueOf(v.getDefaultValue());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_STRING:
|
||||
@@ -201,6 +212,9 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
retval += "TEXT";
|
||||
}
|
||||
}
|
||||
if (v.isHaveDefault()) {
|
||||
retval += " DEFAULT " + v.getDefaultValue();
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BINARY:
|
||||
retval += "BYTEA";
|
||||
|
Reference in New Issue
Block a user