Skip to content

Commit 787b907

Browse files
author
Qinghua Chen
committed
add comment
1 parent 298319d commit 787b907

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

migrate.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ func (ms MigrationSet) ExecMax(db *sql.DB, dialect string, m MigrationSource, di
466466
return ms.applyMigrations(dir, migrations, dbMap)
467467
}
468468

469+
// Returns the number of applied migrations.
469470
func (ms MigrationSet) ExecVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) (int, error) {
470471
migrations, dbMap, err := ms.PlanMigrationToVersion(db, dialect, m, dir, version)
471472
if err != nil {
@@ -474,6 +475,7 @@ func (ms MigrationSet) ExecVersion(db *sql.DB, dialect string, m MigrationSource
474475
return ms.applyMigrations(dir, migrations, dbMap)
475476
}
476477

478+
// Applies the planned migrations and returns the number of applied migrations.
477479
func (ms MigrationSet) applyMigrations(dir MigrationDirection, migrations []*PlannedMigration, dbMap *gorp.DbMap) (int, error) {
478480
applied := 0
479481
for _, migration := range migrations {
@@ -553,15 +555,18 @@ func PlanMigrationToVersion(db *sql.DB, dialect string, m MigrationSource, dir M
553555
return migSet.PlanMigrationToVersion(db, dialect, m, dir, version)
554556
}
555557

558+
// Plan a migration.
556559
func (ms MigrationSet) PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, *gorp.DbMap, error) {
557-
return ms.planMigration(db, dialect, m, dir, max, -1)
560+
return ms.planMigrationCommon(db, dialect, m, dir, max, -1)
558561
}
559562

563+
// Plan a migration to version.
560564
func (ms MigrationSet) PlanMigrationToVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
561-
return ms.planMigration(db, dialect, m, dir, 0, version)
565+
return ms.planMigrationCommon(db, dialect, m, dir, 0, version)
562566
}
563567

564-
func (ms MigrationSet) planMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
568+
// A common method to plan a migration.
569+
func (ms MigrationSet) planMigrationCommon(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
565570
dbMap, err := ms.getMigrationDbMap(db, dialect)
566571
if err != nil {
567572
return nil, nil, err

0 commit comments

Comments
 (0)