refactor: implement dry run feature to validate connections and count source rows without migrating
This commit is contained in:
@@ -23,6 +23,7 @@ func main() {
|
||||
|
||||
configPath := flag.String("config", "", "path to migration config file")
|
||||
validate := flag.Bool("validate", false, "count rows in source and target per job and compare")
|
||||
dryRun := flag.Bool("dry-run", false, "validate connections, storage access, and count source rows without migrating")
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() > 1 {
|
||||
@@ -45,8 +46,6 @@ func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
log.Info("=== Starting migration ===")
|
||||
|
||||
var wgConnect errgroup.Group
|
||||
var sourceDb, targetDb dbwrapper.DbWrapper
|
||||
|
||||
@@ -79,13 +78,29 @@ func main() {
|
||||
defer sourceDb.Close()
|
||||
defer targetDb.Close()
|
||||
|
||||
var azureClient *azure.Client
|
||||
if config.App.AzureStorage.Enabled {
|
||||
var err error
|
||||
azureClient, err = azure.NewClient(config.App.AzureStorage)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create Azure storage client: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if *dryRun {
|
||||
runDryRun(ctx, azureClient, sourceDb, migrationConfig.Jobs, migrationConfig.MaxParallelWorkers)
|
||||
return
|
||||
}
|
||||
|
||||
if *validate {
|
||||
validationResults := validateJobs(ctx, sourceDb, targetDb, migrationConfig.Jobs, migrationConfig.MaxParallelWorkers)
|
||||
printValidationReport(validationResults)
|
||||
return
|
||||
}
|
||||
|
||||
results := processMigrationJobs(ctx, sourceDb, targetDb, migrationConfig.Jobs, migrationConfig.MaxParallelWorkers)
|
||||
log.Info("=== Starting migration ===")
|
||||
|
||||
results := processMigrationJobs(ctx, sourceDb, targetDb, azureClient, migrationConfig.Jobs, migrationConfig.MaxParallelWorkers)
|
||||
|
||||
log.Info("=== RESUMEN DE MIGRACIÓN ===")
|
||||
var totalProcessed, totalErrors int64
|
||||
@@ -116,6 +131,7 @@ func processMigrationJobs(
|
||||
ctx context.Context,
|
||||
sourceDb dbwrapper.DbWrapper,
|
||||
targetDb dbwrapper.DbWrapper,
|
||||
azureClient *azure.Client,
|
||||
jobs []config.Job,
|
||||
maxParallelWorkers int,
|
||||
) []models.JobResult {
|
||||
@@ -143,15 +159,6 @@ func processMigrationJobs(
|
||||
extractor := extractors.NewExtractor(sourceDb)
|
||||
loader := loaders.NewGenericLoader(targetDb)
|
||||
|
||||
var azureClient *azure.Client
|
||||
if config.App.AzureStorage.Enabled {
|
||||
var err error
|
||||
azureClient, err = azure.NewClient(config.App.AzureStorage)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create Azure storage client: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for i := range maxParallelWorkers {
|
||||
wgJobs.Go(func() {
|
||||
for job := range chJobs {
|
||||
|
||||
Reference in New Issue
Block a user