Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ func (ms MigrationSet) planMigrationCommon(db *sql.DB, dialect string, m Migrati
toApply := ToApply(migrations, record.Id, dir)
toApplyCount := len(toApply)

if version >= 0 {
// When a target version is requested but there are no migrations left to
// apply, we are already at that version, so there is nothing to do.
if version >= 0 && len(toApply) > 0 {
targetIndex := 0
for targetIndex < len(toApply) {
tempVersion := toApply[targetIndex].VersionInt()
Expand Down
16 changes: 16 additions & 0 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ func (s *SqliteMigrateSuite) TestMigrateVersionIntFailedWithInvalidVerion(c *C)
c.Assert(err, NotNil)
}

func (s *SqliteMigrateSuite) TestMigrateVersionIntAlreadyAtVersion(c *C) {
migrations := &FileMigrationSource{
Dir: "test-migrations",
}

// Migrate up to the latest version.
n, err := ExecVersion(s.Db, "sqlite3", migrations, Up, 2)
c.Assert(err, IsNil)
c.Assert(n, Equals, 2)

// Requesting the same version again has nothing to apply and must not error.
n, err = ExecVersion(s.Db, "sqlite3", migrations, Up, 2)
c.Assert(err, IsNil)
c.Assert(n, Equals, 0)
}

func (s *SqliteMigrateSuite) TestMigrateDown(c *C) {
migrations := &FileMigrationSource{
Dir: "test-migrations",
Expand Down