feat: add IF NOT EXISTS config for migrator
This commit is contained in:
parent
e57e5d8884
commit
d34abe9128
@ -35,6 +35,7 @@ type Migrator struct {
|
||||
// Config schema config
|
||||
type Config struct {
|
||||
CreateIndexAfterCreateTable bool
|
||||
CreateTableUseIfNotExists bool
|
||||
DB *gorm.DB
|
||||
gorm.Dialector
|
||||
}
|
||||
@ -213,6 +214,10 @@ func (m Migrator) CreateTable(values ...interface{}) error {
|
||||
hasPrimaryKeyInDataType bool
|
||||
)
|
||||
|
||||
if m.CreateTableUseIfNotExists {
|
||||
createTableSQL = "CREATE TABLE IF NOT EXISTS ? ("
|
||||
}
|
||||
|
||||
for _, dbName := range stmt.Schema.DBNames {
|
||||
field := stmt.Schema.FieldsByDBName[dbName]
|
||||
if !field.IgnoreMigration {
|
||||
|
Loading…
x
Reference in New Issue
Block a user