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
11 changes: 11 additions & 0 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type MigrationSet struct {
//
// This should be used sparingly as it is removing a safety check.
IgnoreUnknown bool
// DisableCreateTable disable the creation of the migration table
DisableCreateTable bool
}

var migSet = MigrationSet{}
Expand Down Expand Up @@ -106,6 +108,11 @@ func SetSchema(name string) {
}
}

// SetDisableCreateTable sets the boolean to disable the creation of the migration table
func SetDisableCreateTable(disable bool) {
migSet.DisableCreateTable = disable
}

// SetIgnoreUnknown sets the flag that skips database check to see if there is a
// migration in the database that is not in migration source.
//
Expand Down Expand Up @@ -752,6 +759,10 @@ Check https://github.com/go-sql-driver/mysql#parsetime for more info.`)
table.ColMap("Id").SetMaxSize(4000)
}

if migSet.DisableCreateTable {
return dbMap, nil
}

err := dbMap.CreateTablesIfNotExists()
if err != nil {
// Oracle database does not support `if not exists`, so use `ORA-00955:` error code
Expand Down
17 changes: 17 additions & 0 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,20 @@ func (s *SqliteMigrateSuite) TestRunMigrationObjOtherTable(c *C) {
c.Assert(err, IsNil)
c.Assert(n, Equals, 0)
}

func (s *SqliteMigrateSuite) TestSetDisableCreateTable(c *C) {
c.Assert(migSet.DisableCreateTable, Equals, false)

SetDisableCreateTable(true)
c.Assert(migSet.DisableCreateTable, Equals, true)

SetDisableCreateTable(false)
c.Assert(migSet.DisableCreateTable, Equals, false)
}

func (s *SqliteMigrateSuite) TestGetMigrationDbMapWithDisableCreateTable(c *C) {
SetDisableCreateTable(false)

_, err := migSet.getMigrationDbMap(s.Db, "postgres")
c.Assert(err, IsNil)
}