File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ type MigrationSet struct {
37
37
//
38
38
// This should be used sparingly as it is removing a safety check.
39
39
IgnoreUnknown bool
40
+ // DisableCreateTable disable the creation of the migration table
41
+ DisableCreateTable bool
40
42
}
41
43
42
44
var migSet = MigrationSet {}
@@ -106,6 +108,11 @@ func SetSchema(name string) {
106
108
}
107
109
}
108
110
111
+ // SetDisableCreateTable sets the boolean to disable the creation of the migration table
112
+ func SetDisableCreateTable (disable bool ) {
113
+ migSet .DisableCreateTable = disable
114
+ }
115
+
109
116
// SetIgnoreUnknown sets the flag that skips database check to see if there is a
110
117
// migration in the database that is not in migration source.
111
118
//
@@ -752,6 +759,10 @@ Check https://github.com/go-sql-driver/mysql#parsetime for more info.`)
752
759
table .ColMap ("Id" ).SetMaxSize (4000 )
753
760
}
754
761
762
+ if migSet .DisableCreateTable {
763
+ return dbMap , nil
764
+ }
765
+
755
766
err := dbMap .CreateTablesIfNotExists ()
756
767
if err != nil {
757
768
// 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) {
648
648
c .Assert (err , IsNil )
649
649
c .Assert (n , Equals , 0 )
650
650
}
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