File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
4244var 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments