(value interface{}, field *schema.Field, columnType gorm.ColumnType)
| 597 | } |
| 598 | |
| 599 | func (m Migrator) MigrateColumnUnique(value interface{}, field *schema.Field, columnType gorm.ColumnType) error { |
| 600 | unique, ok := columnType.Unique() |
| 601 | if !ok || field.PrimaryKey { |
| 602 | return nil // skip primary key |
| 603 | } |
| 604 | // By default, ColumnType's Unique is not affected by UniqueIndex, so we don't care about UniqueIndex. |
| 605 | return m.RunWithValue(value, func(stmt *gorm.Statement) error { |
| 606 | // We're currently only receiving boolean values on `Unique` tag, |
| 607 | // so the UniqueConstraint name is fixed |
| 608 | constraint := m.DB.NamingStrategy.UniqueName(stmt.Table, field.DBName) |
| 609 | if unique && !field.Unique { |
| 610 | return m.DB.Migrator().DropConstraint(value, constraint) |
| 611 | } |
| 612 | if !unique && field.Unique { |
| 613 | return m.DB.Migrator().CreateConstraint(value, constraint) |
| 614 | } |
| 615 | return nil |
| 616 | }) |
| 617 | } |
| 618 | |
| 619 | // ColumnTypes return columnTypes []gorm.ColumnType and execErr error |
| 620 | func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) { |
nothing calls this directly
no test coverage detected