Add field tag to ignore migration
This commit is contained in:
parent
7598204dc3
commit
bce40e6d6a
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ TODO*
|
||||
documents
|
||||
coverage.txt
|
||||
_book
|
||||
.idea
|
||||
|
@ -396,7 +396,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
|
||||
}
|
||||
}
|
||||
|
||||
if alterColumn {
|
||||
if alterColumn && !field.IgnoreMigration {
|
||||
return m.DB.Migrator().AlterColumn(value, field.Name)
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ type Field struct {
|
||||
ReflectValueOf func(reflect.Value) reflect.Value
|
||||
ValueOf func(reflect.Value) (value interface{}, zero bool)
|
||||
Set func(reflect.Value, interface{}) error
|
||||
IgnoreMigration bool
|
||||
}
|
||||
|
||||
func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
||||
@ -188,6 +189,10 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
||||
field.Comment = val
|
||||
}
|
||||
|
||||
if _, ok := field.TagSettings["IGNOREMIGRATION"]; ok {
|
||||
field.IgnoreMigration = true
|
||||
}
|
||||
|
||||
// default value is function or null or blank (primary keys)
|
||||
skipParseDefaultValue := strings.Contains(field.DefaultValue, "(") &&
|
||||
strings.Contains(field.DefaultValue, ")") || strings.ToLower(field.DefaultValue) == "null" || field.DefaultValue == ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user