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