Skip to content

Commit 9f02b1e

Browse files
authored
Merge pull request #199 from akhorsi/master
Add disable option to avoid creating migration table on getting db map
2 parents 55d5740 + aad1dd2 commit 9f02b1e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

migrate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type MigrationSet struct {
3737
//
3838
// This should be used sparingly as it is removing a safety check.
3939
IgnoreUnknown bool
40+
// DisableCreateTable disable the creation of the migration table
41+
DisableCreateTable bool
4042
}
4143

4244
var migSet = MigrationSet{}
@@ -106,6 +108,11 @@ func SetSchema(name string) {
106108
}
107109
}
108110

111+
// SetDisableCreateTable sets the boolean to disable the creation of the migration table
112+
func SetDisableCreateTable(disable bool) {
113+
migSet.DisableCreateTable = disable
114+
}
115+
109116
// SetIgnoreUnknown sets the flag that skips database check to see if there is a
110117
// migration in the database that is not in migration source.
111118
//
@@ -752,6 +759,10 @@ Check https://github.com/go-sql-driver/mysql#parsetime for more info.`)
752759
table.ColMap("Id").SetMaxSize(4000)
753760
}
754761

762+
if migSet.DisableCreateTable {
763+
return dbMap, nil
764+
}
765+
755766
err := dbMap.CreateTablesIfNotExists()
756767
if err != nil {
757768
// Oracle database does not support `if not exists`, so use `ORA-00955:` error code

migrate_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,20 @@ func (s *SqliteMigrateSuite) TestRunMigrationObjOtherTable(c *C) {
648648
c.Assert(err, IsNil)
649649
c.Assert(n, Equals, 0)
650650
}
651+
652+
func (s *SqliteMigrateSuite) TestSetDisableCreateTable(c *C) {
653+
c.Assert(migSet.DisableCreateTable, Equals, false)
654+
655+
SetDisableCreateTable(true)
656+
c.Assert(migSet.DisableCreateTable, Equals, true)
657+
658+
SetDisableCreateTable(false)
659+
c.Assert(migSet.DisableCreateTable, Equals, false)
660+
}
661+
662+
func (s *SqliteMigrateSuite) TestGetMigrationDbMapWithDisableCreateTable(c *C) {
663+
SetDisableCreateTable(false)
664+
665+
_, err := migSet.getMigrationDbMap(s.Db, "postgres")
666+
c.Assert(err, IsNil)
667+
}

0 commit comments

Comments
 (0)