feat: implement MSSQL data extraction and transformation process

This commit is contained in:
2026-04-06 20:36:11 -05:00
parent 382c2099f7
commit f589664320
4 changed files with 89 additions and 5 deletions

View File

@@ -1,7 +1,10 @@
package main
import (
"context"
"database/sql"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
_ "github.com/microsoft/go-mssqldb"
@@ -17,12 +20,16 @@ func processMigrationJob(sourceDb *sql.DB, targetDb *pgxpool.Pool, job Migration
logColumnTypes(sourceColTypes, "Source col types")
logColumnTypes(targetColTypes, "Target col types")
sourceQuery := buildExtractQueryMssql(job, sourceColTypes)
chRowsExtract := make(chan []UnknownRowValues, QueueSize)
log.Debug(sourceQuery)
mssqlContext := context.Background()
targetQuery := buildExtractQueryPostgres(job, targetColTypes)
log.Debug(targetQuery)
if err := extractFromMssql(mssqlContext, job, sourceColTypes, ChunkSize, sourceDb, chRowsExtract); err != nil {
log.Fatal("Unexpected error extrating data from mssql: ", err)
}
close(chRowsExtract)
transformRowsMssql(job, sourceColTypes, chRowsExtract)
}
func logColumnTypes(columnTypes []ColumnType, label string) {
@@ -32,3 +39,22 @@ func logColumnTypes(columnTypes []ColumnType, label string) {
log.Infof("%+v", col)
}
}
func transformRowsMssql(job MigrationJob, columns []ColumnType, in <-chan []UnknownRowValues) {
for rows := range in {
log.Debug("Chunk received, transforming...")
for i, rowValues := range rows {
if i%100 == 0 {
logSampleRow(job, columns, rowValues, fmt.Sprintf("row %d", i))
}
}
}
}
func logSampleRow(job MigrationJob, columns []ColumnType, rowValues UnknownRowValues, tag string) {
log.Infof("[%s.%s] Sample row: (%s)", job.Schema, job.Table, tag)
for i, col := range columns {
log.Infof("%s: %v", col.Name(), rowValues[i])
}
}