@@ -382,10 +382,13 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
382
382
if err != nil {
383
383
return err
384
384
}
385
+
385
386
rows , err := this .db .Query (query )
386
387
if err != nil {
387
388
return err
388
389
}
390
+ defer rows .Close ()
391
+
389
392
for rows .Next () {
390
393
this .migrationContext .MigrationRangeMinValues = sql .NewColumnValues (uniqueKey .Len ())
391
394
if err = rows .Scan (this .migrationContext .MigrationRangeMinValues .ValuesPointers ... ); err != nil {
@@ -394,8 +397,7 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
394
397
}
395
398
this .migrationContext .Log .Infof ("Migration min values: [%s]" , this .migrationContext .MigrationRangeMinValues )
396
399
397
- err = rows .Err ()
398
- return err
400
+ return rows .Err ()
399
401
}
400
402
401
403
// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
@@ -405,10 +407,13 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
405
407
if err != nil {
406
408
return err
407
409
}
410
+
408
411
rows , err := this .db .Query (query )
409
412
if err != nil {
410
413
return err
411
414
}
415
+ defer rows .Close ()
416
+
412
417
for rows .Next () {
413
418
this .migrationContext .MigrationRangeMaxValues = sql .NewColumnValues (uniqueKey .Len ())
414
419
if err = rows .Scan (this .migrationContext .MigrationRangeMaxValues .ValuesPointers ... ); err != nil {
@@ -417,8 +422,7 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
417
422
}
418
423
this .migrationContext .Log .Infof ("Migration max values: [%s]" , this .migrationContext .MigrationRangeMaxValues )
419
424
420
- err = rows .Err ()
421
- return err
425
+ return rows .Err ()
422
426
}
423
427
424
428
// ReadMigrationRangeValues reads min/max values that will be used for rowcopy.
@@ -479,10 +483,13 @@ func (this *Applier) CalculateNextIterationRangeEndValues() (hasFurtherRange boo
479
483
if err != nil {
480
484
return hasFurtherRange , err
481
485
}
486
+
482
487
rows , err := this .db .Query (query , explodedArgs ... )
483
488
if err != nil {
484
489
return hasFurtherRange , err
485
490
}
491
+ defer rows .Close ()
492
+
486
493
iterationRangeMaxValues := sql .NewColumnValues (this .migrationContext .UniqueKey .Len ())
487
494
for rows .Next () {
488
495
if err = rows .Scan (iterationRangeMaxValues .ValuesPointers ... ); err != nil {
0 commit comments