mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql/schema: fix postgres index migration (#1351)
Fix PostgreSQL index migration when table_name = type_name. Closed #1344
This commit is contained in:
@@ -390,9 +390,7 @@ func (m *Migrate) changeSet(curr, new *Table) (*changes, error) {
|
||||
|
||||
// Drop indexes.
|
||||
for _, idx := range curr.Indexes {
|
||||
_, ok1 := new.fk(idx.Name)
|
||||
_, ok2 := new.index(idx.Name)
|
||||
if !ok1 && !ok2 {
|
||||
if _, isFK := new.fk(idx.Name); !isFK && !new.hasIndex(idx.Name, idx.realname) {
|
||||
change.index.drop.append(idx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user