feat: enhance mssql configuration and update extraction script

This commit is contained in:
2026-04-03 22:55:30 -05:00
parent 7eaa3478e1
commit b04f1315af
2 changed files with 40 additions and 14 deletions

View File

@@ -9,7 +9,9 @@ import (
type appConfig struct {
SourceDbUrl string
SourceDbType string
TargetDbUrl string
TargetDbType string
}
func loadEnv() {
@@ -27,14 +29,26 @@ func getAppConfig() appConfig {
log.Fatal("SOURCE_DB_URL environment variable not set")
}
sourceDbType := os.Getenv("SOURCE_DB_TYPE")
if sourceDbType == "" {
log.Fatal("SOURCE_DB_TYPE environment variable not set")
}
targetDbUrl := os.Getenv("TARGET_DB_URL")
if targetDbUrl == "" {
log.Fatal("TARGET_DB_URL environment variable not set")
}
targetDbType := os.Getenv("TARGET_DB_TYPE")
if targetDbType == "" {
log.Fatal("TARGET_DB_TYPE environment variable not set")
}
return appConfig{
SourceDbUrl: sourceDbUrl,
SourceDbType: sourceDbType,
TargetDbUrl: targetDbUrl,
TargetDbType: targetDbType,
}
}

View File

@@ -26,11 +26,10 @@ func main() {
ctx := context.Background()
schema := "test"
table := "migration_test"
colNames := []string{"id", "nombre_producto", "descripcion", "stock", "precio", "es_activo", "fecha_creacion", "ultima_actualizacion", "configuracion_json", "etiquetas", "binario_test", "ip_servidor", "rango_prueba_min", "rango_prueba_max"}
schema := "Cartografia"
table := "MANZANA"
query := buildExtractSqlSentence(schema, table, colNames)
query := buildExtractSqlSentence(schema, table, []string{})
rows, err := db.QueryContext(ctx, query)
if err != nil {
@@ -46,6 +45,15 @@ func main() {
scanArgs[i] = &values[i]
}
colTypes, err := rows.ColumnTypes()
if err != nil {
log.Fatal(err)
}
for _, col := range colTypes {
log.Debugf("%+v", col)
}
count := 0
for rows.Next() {
if err := rows.Scan(scanArgs...); err != nil {
@@ -72,6 +80,9 @@ func main() {
func buildExtractSqlSentence(schema, table string, colNames []string) string {
var sbColumns strings.Builder
if len(colNames) == 0 {
sbColumns.WriteString("*")
} else {
for i, col := range colNames {
sbColumns.WriteString(`[`)
sbColumns.WriteString(col)
@@ -80,6 +91,7 @@ func buildExtractSqlSentence(schema, table string, colNames []string) string {
sbColumns.WriteString(", ")
}
}
}
return fmt.Sprintf(`SELECT %s FROM [%s].[%s] WITH (NOLOCK)`, sbColumns.String(), schema, table)
}