diff --git a/sync.go b/sync.go index 275f5b6..ac73b70 100644 --- a/sync.go +++ b/sync.go @@ -41,11 +41,6 @@ func (job JobConfig) syncTargets() (string, []SyncResult, error) { primaryKeyIndices: primaryKeyIndices, columns: job.Columns, } - - // Connect to each target - if err := targets[i].connect(); err != nil { - return "", nil, err - } } // Get all rows from the source table and put them in a map by their primary key @@ -70,6 +65,15 @@ func (job JobConfig) syncTargets() (string, []SyncResult, error) { go func(target table) { defer wg.Done() + // Connect to each target + if err := target.connect(); err != nil { + resultChan <- SyncResult{ + Target: target.config, + Error: err, + } + return + } + checksum, synced, err := target.syncTarget(sourceChecksum, sourceMap) target.Close() // Close the target's connection pool