feat: enhance mssql configuration and update extraction script
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
)
|
||||
|
||||
type appConfig struct {
|
||||
SourceDbUrl string
|
||||
TargetDbUrl string
|
||||
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,
|
||||
TargetDbUrl: targetDbUrl,
|
||||
SourceDbUrl: sourceDbUrl,
|
||||
SourceDbType: sourceDbType,
|
||||
TargetDbUrl: targetDbUrl,
|
||||
TargetDbType: targetDbType,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,12 +80,16 @@ func main() {
|
||||
func buildExtractSqlSentence(schema, table string, colNames []string) string {
|
||||
var sbColumns strings.Builder
|
||||
|
||||
for i, col := range colNames {
|
||||
sbColumns.WriteString(`[`)
|
||||
sbColumns.WriteString(col)
|
||||
sbColumns.WriteString(`]`)
|
||||
if i < len(colNames)-1 {
|
||||
sbColumns.WriteString(", ")
|
||||
if len(colNames) == 0 {
|
||||
sbColumns.WriteString("*")
|
||||
} else {
|
||||
for i, col := range colNames {
|
||||
sbColumns.WriteString(`[`)
|
||||
sbColumns.WriteString(col)
|
||||
sbColumns.WriteString(`]`)
|
||||
if i < len(colNames)-1 {
|
||||
sbColumns.WriteString(", ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user