HasConstraint check has constraint or not
(value interface{}, name string)
| 787 | |
| 788 | // HasConstraint check has constraint or not |
| 789 | func (m Migrator) HasConstraint(value interface{}, name string) bool { |
| 790 | var count int64 |
| 791 | m.RunWithValue(value, func(stmt *gorm.Statement) error { |
| 792 | currentDatabase := m.DB.Migrator().CurrentDatabase() |
| 793 | constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) |
| 794 | if constraint != nil { |
| 795 | name = constraint.GetName() |
| 796 | } |
| 797 | |
| 798 | return m.DB.Raw( |
| 799 | "SELECT count(*) FROM INFORMATION_SCHEMA.table_constraints WHERE constraint_schema = ? AND table_name = ? AND constraint_name = ?", |
| 800 | currentDatabase, table, name, |
| 801 | ).Row().Scan(&count) |
| 802 | }) |
| 803 | |
| 804 | return count > 0 |
| 805 | } |
| 806 | |
| 807 | // BuildIndexOptions build index options |
| 808 | func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{}) { |
nothing calls this directly
no test coverage detected