feat: streamline data extraction from MSSQL and Postgres, add UUID transformation
This commit is contained in:
@@ -23,16 +23,11 @@ func processMigrationJob(sourceDb *sql.DB, targetDb *pgxpool.Pool, job Migration
|
|||||||
|
|
||||||
chRowsExtract := make(chan []UnknownRowValues, QueueSize)
|
chRowsExtract := make(chan []UnknownRowValues, QueueSize)
|
||||||
mssqlContext := context.Background()
|
mssqlContext := context.Background()
|
||||||
var wgMssqlExtractors sync.WaitGroup
|
|
||||||
|
|
||||||
wgMssqlExtractors.Go(func() {
|
go func() {
|
||||||
if err := extractFromMssql(mssqlContext, job, sourceColTypes, ChunkSize, sourceDb, chRowsExtract); err != nil {
|
if err := extractFromMssql(mssqlContext, job, sourceColTypes, ChunkSize, sourceDb, chRowsExtract); err != nil {
|
||||||
log.Error("Unexpected error extrating data from mssql: ", err)
|
log.Error("Unexpected error extrating data from mssql: ", err)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
wgMssqlExtractors.Wait()
|
|
||||||
close(chRowsExtract)
|
close(chRowsExtract)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -44,16 +39,11 @@ func processMigrationJob(sourceDb *sql.DB, targetDb *pgxpool.Pool, job Migration
|
|||||||
|
|
||||||
chRowsExtractPostgres := make(chan []UnknownRowValues, QueueSize)
|
chRowsExtractPostgres := make(chan []UnknownRowValues, QueueSize)
|
||||||
postgresContext := context.Background()
|
postgresContext := context.Background()
|
||||||
var wgPostgresExtractors sync.WaitGroup
|
|
||||||
|
|
||||||
wgPostgresExtractors.Go(func() {
|
go func() {
|
||||||
if err := extractFromPostgres(postgresContext, job, sourceColTypes, ChunkSize, targetDb, chRowsExtractPostgres); err != nil {
|
if err := extractFromPostgres(postgresContext, job, sourceColTypes, ChunkSize, targetDb, chRowsExtractPostgres); err != nil {
|
||||||
log.Error("Unexpected error extrating data from postgres: ", err)
|
log.Error("Unexpected error extrating data from postgres: ", err)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
wgPostgresExtractors.Wait()
|
|
||||||
close(chRowsExtractPostgres)
|
close(chRowsExtractPostgres)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -78,6 +68,15 @@ func transformRows(job MigrationJob, columns []ColumnType, driver string, in <-c
|
|||||||
log.Debugf("Chunk received (%s), transforming...", driver)
|
log.Debugf("Chunk received (%s), transforming...", driver)
|
||||||
|
|
||||||
for i, rowValues := range rows {
|
for i, rowValues := range rows {
|
||||||
|
for i, col := range columns {
|
||||||
|
value := rowValues[i]
|
||||||
|
if col.SystemType() == "uniqueidentifier" && driver == "sqlserver" {
|
||||||
|
if b, ok := value.([]byte); ok {
|
||||||
|
rowValues[i] = mssqlUuidToBigEndian(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if i%100 == 0 {
|
if i%100 == 0 {
|
||||||
logSampleRow(job, columns, rowValues, fmt.Sprintf("row %d", i))
|
logSampleRow(job, columns, rowValues, fmt.Sprintf("row %d", i))
|
||||||
}
|
}
|
||||||
@@ -91,3 +90,16 @@ func logSampleRow(job MigrationJob, columns []ColumnType, rowValues UnknownRowVa
|
|||||||
log.Infof("%s: %v", col.Name(), rowValues[i])
|
log.Infof("%s: %v", col.Name(), rowValues[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mssqlUuidToBigEndian(mssqlUuid []byte) []byte {
|
||||||
|
if len(mssqlUuid) != 16 {
|
||||||
|
return mssqlUuid
|
||||||
|
}
|
||||||
|
pgUuid := make([]byte, 16)
|
||||||
|
pgUuid[0], pgUuid[1], pgUuid[2], pgUuid[3] = mssqlUuid[3], mssqlUuid[2], mssqlUuid[1], mssqlUuid[0]
|
||||||
|
pgUuid[4], pgUuid[5] = mssqlUuid[5], mssqlUuid[4]
|
||||||
|
pgUuid[6], pgUuid[7] = mssqlUuid[7], mssqlUuid[6]
|
||||||
|
copy(pgUuid[8:], mssqlUuid[8:])
|
||||||
|
|
||||||
|
return pgUuid
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user