in schema/field.go
1.Add UniqueIndex field to Field's struct。 2.Resolve UniqueIndex value from StructField. in migrator/migrator.go -> MigrateColumn 1.check unique, Check for the uniqueIndex and unique simultaneously
This commit is contained in:
parent
373bcf7aca
commit
42dee40a4e
@ -440,7 +440,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check unique
|
// check unique
|
||||||
if unique, ok := columnType.Unique(); ok && unique != field.Unique {
|
if unique, ok := columnType.Unique(); ok && !(unique == field.Unique || unique == field.UniqueIndex) {
|
||||||
// not primary key
|
// not primary key
|
||||||
if !field.PrimaryKey {
|
if !field.PrimaryKey {
|
||||||
alterColumn = true
|
alterColumn = true
|
||||||
|
@ -69,6 +69,7 @@ type Field struct {
|
|||||||
DefaultValueInterface interface{}
|
DefaultValueInterface interface{}
|
||||||
NotNull bool
|
NotNull bool
|
||||||
Unique bool
|
Unique bool
|
||||||
|
UniqueIndex bool
|
||||||
Comment string
|
Comment string
|
||||||
Size int
|
Size int
|
||||||
Precision int
|
Precision int
|
||||||
@ -114,6 +115,7 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
|||||||
HasDefaultValue: utils.CheckTruth(tagSetting["AUTOINCREMENT"]),
|
HasDefaultValue: utils.CheckTruth(tagSetting["AUTOINCREMENT"]),
|
||||||
NotNull: utils.CheckTruth(tagSetting["NOT NULL"], tagSetting["NOTNULL"]),
|
NotNull: utils.CheckTruth(tagSetting["NOT NULL"], tagSetting["NOTNULL"]),
|
||||||
Unique: utils.CheckTruth(tagSetting["UNIQUE"]),
|
Unique: utils.CheckTruth(tagSetting["UNIQUE"]),
|
||||||
|
UniqueIndex: utils.CheckTruth(tagSetting["UNIQUEINDEX"]),
|
||||||
Comment: tagSetting["COMMENT"],
|
Comment: tagSetting["COMMENT"],
|
||||||
AutoIncrementIncrement: 1,
|
AutoIncrementIncrement: 1,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user