CreateConstraint create constraint
(value interface{}, name string)
| 760 | |
| 761 | // CreateConstraint create constraint |
| 762 | func (m Migrator) CreateConstraint(value interface{}, name string) error { |
| 763 | return m.RunWithValue(value, func(stmt *gorm.Statement) error { |
| 764 | constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) |
| 765 | if constraint != nil { |
| 766 | vars := []interface{}{clause.Table{Name: table}} |
| 767 | if stmt.TableExpr != nil { |
| 768 | vars[0] = stmt.TableExpr |
| 769 | } |
| 770 | sql, values := constraint.Build() |
| 771 | return m.DB.Exec("ALTER TABLE ? ADD "+sql, append(vars, values...)...).Error |
| 772 | } |
| 773 | return nil |
| 774 | }) |
| 775 | } |
| 776 | |
| 777 | // DropConstraint drop constraint |
| 778 | func (m Migrator) DropConstraint(value interface{}, name string) error { |
nothing calls this directly
no test coverage detected