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