Skip to content
Merged
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
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