Skip to content

Commit

Permalink
Merge pull request #242 from peterldowns/patch-1
Browse files Browse the repository at this point in the history
Fix DisableCreateTable for MigrationSet instances.
  • Loading branch information
rubenv authored Jun 5, 2023
2 parents 61ee1bf + 7393377 commit 345d0b1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ Check https://github.com/go-sql-driver/mysql#parsetime for more info.`)
table.ColMap("Id").SetMaxSize(4000)
}

if migSet.DisableCreateTable {
if ms.DisableCreateTable {
return dbMap, nil
}

Expand Down
48 changes: 48 additions & 0 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,54 @@ func (s *SqliteMigrateSuite) TestGetMigrationDbMapWithDisableCreateTable(c *C) {
c.Assert(err, IsNil)
}

// If ms.DisableCreateTable == true, then the the migrations table should not be
// created, regardless of the global migSet.DisableCreateTable setting.
func (s *SqliteMigrateSuite) TestGetMigrationObjDbMapWithDisableCreateTableTrue(c *C) {
SetDisableCreateTable(false)
ms := MigrationSet{
DisableCreateTable: true,
TableName: "silly_example_table",
}
c.Assert(migSet.DisableCreateTable, Equals, false)
c.Assert(ms.DisableCreateTable, Equals, true)

dbMap, err := ms.getMigrationDbMap(s.Db, "sqlite3")
c.Assert(err, IsNil)
c.Assert(dbMap, NotNil)

tableNameIfExists, err := s.DbMap.SelectNullStr(
"SELECT name FROM sqlite_master WHERE type='table' AND name=$1",
ms.TableName,
)
c.Assert(err, IsNil)
c.Assert(tableNameIfExists.Valid, Equals, false)
}

// If ms.DisableCreateTable == false, then the the migrations table should not be
// created, regardless of the global migSet.DisableCreateTable setting.
func (s *SqliteMigrateSuite) TestGetMigrationObjDbMapWithDisableCreateTableFalse(c *C) {
SetDisableCreateTable(true)
defer SetDisableCreateTable(false) // reset the global state when the test ends.
ms := MigrationSet{
DisableCreateTable: false,
TableName: "silly_example_table",
}
c.Assert(migSet.DisableCreateTable, Equals, true)
c.Assert(ms.DisableCreateTable, Equals, false)

dbMap, err := ms.getMigrationDbMap(s.Db, "sqlite3")
c.Assert(err, IsNil)
c.Assert(dbMap, NotNil)

tableNameIfExists, err := s.DbMap.SelectNullStr(
"SELECT name FROM sqlite_master WHERE type='table' AND name=$1",
ms.TableName,
)
c.Assert(err, IsNil)
c.Assert(tableNameIfExists.Valid, Equals, true)
c.Assert(tableNameIfExists.String, Equals, ms.TableName)
}

func (s *SqliteMigrateSuite) TestContextTimeout(c *C) {
// This statement will run for a long time: 1,000,000 iterations of the fibonacci sequence
fibonacciLoopStmt := `WITH RECURSIVE
Expand Down

0 comments on commit 345d0b1

Please sign in to comment.