dialect/sql/schema: fix postgres index migration (#1351)

Fix PostgreSQL index migration when table_name = type_name.
Closed #1344
This commit is contained in:
Ariel Mashraki
2021-03-18 22:29:39 +02:00
committed by GitHub
parent 14ed353ca9
commit b4ad29f7f3
6 changed files with 50 additions and 26 deletions

View File

@@ -139,6 +139,19 @@ func (t *Table) index(name string) (*Index, bool) {
return nil, false
}
// hasIndex reports if the table has at least one index that matches the given names.
func (t *Table) hasIndex(names ...string) bool {
for i := range names {
if names[i] == "" {
continue
}
if _, ok := t.index(names[i]); ok {
return true
}
}
return false
}
// fk returns a table foreign-key by its symbol.
// faster than map lookup for most cases.
func (t *Table) fk(symbol string) (*ForeignKey, bool) {