refactor: add reverse configuration and enhance transformation logic for PostgreSQL to SQL Server migration
This commit is contained in:
@@ -64,12 +64,28 @@ func computePostgresTransformationPlan(columns []models.ColumnType) []etl.Column
|
||||
|
||||
for i, col := range columns {
|
||||
switch col.SystemType() {
|
||||
case "int2", "int4", "int8", "integer", "smallint", "bigint":
|
||||
plan = append(plan, etl.ColumnTransformPlan{
|
||||
Index: i,
|
||||
Fn: func(v any) (any, error) {
|
||||
if v64, ok := ToInt64(v); ok {
|
||||
return v64, nil
|
||||
}
|
||||
return v, nil
|
||||
},
|
||||
})
|
||||
|
||||
case "uuid":
|
||||
plan = append(plan, etl.ColumnTransformPlan{
|
||||
Index: i,
|
||||
Fn: func(v any) (any, error) {
|
||||
if b, ok := v.([]byte); ok && b != nil {
|
||||
return bigEndianToMssqlUuid(b)
|
||||
switch b := v.(type) {
|
||||
case []byte:
|
||||
if b != nil {
|
||||
return bigEndianToMssqlUuid(b)
|
||||
}
|
||||
case [16]byte:
|
||||
return bigEndianToMssqlUuid(b[:])
|
||||
}
|
||||
return v, nil
|
||||
},
|
||||
|
||||
@@ -82,31 +82,9 @@ func ewkbToMssqlGeo(ewkb []byte, isGeography bool) ([]byte, error) {
|
||||
if len(ewkb) < 5 {
|
||||
return nil, errors.New("Invalid ewkb")
|
||||
}
|
||||
|
||||
var byteOrder binary.ByteOrder
|
||||
if ewkb[0] == 0 {
|
||||
byteOrder = binary.BigEndian
|
||||
} else {
|
||||
byteOrder = binary.LittleEndian
|
||||
}
|
||||
|
||||
wkbType := byteOrder.Uint32(ewkb[1:5])
|
||||
|
||||
var wkb []byte
|
||||
if wkbType&sridFlag != 0 {
|
||||
if len(ewkb) < 9 {
|
||||
return nil, errors.New("Invalid ewkb: SRID flag set but data too short")
|
||||
}
|
||||
clearType := wkbType &^ uint32(sridFlag)
|
||||
wkb = make([]byte, len(ewkb)-4)
|
||||
wkb[0] = ewkb[0]
|
||||
byteOrder.PutUint32(wkb[1:5], clearType)
|
||||
copy(wkb[5:], ewkb[9:])
|
||||
} else {
|
||||
wkb = ewkb
|
||||
}
|
||||
|
||||
return mssqlclrgeo.WkbToUdtGeo(wkb, isGeography)
|
||||
// mssqlclrgeo reads the SRID flag and bytes directly from EWKB,
|
||||
// so no pre-processing needed — pass through as-is.
|
||||
return mssqlclrgeo.WkbToUdtGeo(ewkb, isGeography)
|
||||
}
|
||||
|
||||
func ToInt64(v any) (int64, bool) {
|
||||
|
||||
Reference in New Issue
Block a user