feat: enhance mssql configuration and update extraction script
This commit is contained in:
@@ -9,7 +9,9 @@ import (
|
|||||||
|
|
||||||
type appConfig struct {
|
type appConfig struct {
|
||||||
SourceDbUrl string
|
SourceDbUrl string
|
||||||
|
SourceDbType string
|
||||||
TargetDbUrl string
|
TargetDbUrl string
|
||||||
|
TargetDbType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadEnv() {
|
func loadEnv() {
|
||||||
@@ -27,14 +29,26 @@ func getAppConfig() appConfig {
|
|||||||
log.Fatal("SOURCE_DB_URL environment variable not set")
|
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")
|
targetDbUrl := os.Getenv("TARGET_DB_URL")
|
||||||
if targetDbUrl == "" {
|
if targetDbUrl == "" {
|
||||||
log.Fatal("TARGET_DB_URL environment variable not set")
|
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{
|
return appConfig{
|
||||||
SourceDbUrl: sourceDbUrl,
|
SourceDbUrl: sourceDbUrl,
|
||||||
|
SourceDbType: sourceDbType,
|
||||||
TargetDbUrl: targetDbUrl,
|
TargetDbUrl: targetDbUrl,
|
||||||
|
TargetDbType: targetDbType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,10 @@ func main() {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
schema := "test"
|
schema := "Cartografia"
|
||||||
table := "migration_test"
|
table := "MANZANA"
|
||||||
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"}
|
|
||||||
|
|
||||||
query := buildExtractSqlSentence(schema, table, colNames)
|
query := buildExtractSqlSentence(schema, table, []string{})
|
||||||
|
|
||||||
rows, err := db.QueryContext(ctx, query)
|
rows, err := db.QueryContext(ctx, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -46,6 +45,15 @@ func main() {
|
|||||||
scanArgs[i] = &values[i]
|
scanArgs[i] = &values[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colTypes, err := rows.ColumnTypes()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, col := range colTypes {
|
||||||
|
log.Debugf("%+v", col)
|
||||||
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
if err := rows.Scan(scanArgs...); err != nil {
|
if err := rows.Scan(scanArgs...); err != nil {
|
||||||
@@ -72,6 +80,9 @@ func main() {
|
|||||||
func buildExtractSqlSentence(schema, table string, colNames []string) string {
|
func buildExtractSqlSentence(schema, table string, colNames []string) string {
|
||||||
var sbColumns strings.Builder
|
var sbColumns strings.Builder
|
||||||
|
|
||||||
|
if len(colNames) == 0 {
|
||||||
|
sbColumns.WriteString("*")
|
||||||
|
} else {
|
||||||
for i, col := range colNames {
|
for i, col := range colNames {
|
||||||
sbColumns.WriteString(`[`)
|
sbColumns.WriteString(`[`)
|
||||||
sbColumns.WriteString(col)
|
sbColumns.WriteString(col)
|
||||||
@@ -80,6 +91,7 @@ func buildExtractSqlSentence(schema, table string, colNames []string) string {
|
|||||||
sbColumns.WriteString(", ")
|
sbColumns.WriteString(", ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(`SELECT %s FROM [%s].[%s] WITH (NOLOCK)`, sbColumns.String(), schema, table)
|
return fmt.Sprintf(`SELECT %s FROM [%s].[%s] WITH (NOLOCK)`, sbColumns.String(), schema, table)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user