mirror of
https://github.com/ent/ent.git
synced 2026-05-04 16:40:55 +03:00
dialect/sql/schema: correctly check pg unique constraint
This commit is contained in:
@@ -108,7 +108,13 @@ func (t *Table) index(name string) (*Index, bool) {
|
||||
}
|
||||
// If it is an "implicit index" (unique constraint on
|
||||
// table creation) and it didn't load on table scanning.
|
||||
if c, ok := t.column(name); ok && c.Unique {
|
||||
c, ok := t.column(name)
|
||||
if !ok {
|
||||
// Postgres naming convention for unique constraint.
|
||||
name = strings.TrimSuffix(name, "_key")
|
||||
c, ok = t.column(name)
|
||||
}
|
||||
if ok && c.Unique {
|
||||
return &Index{Name: name, Unique: c.Unique, Columns: []*Column{c}, columns: []string{c.Name}}, true
|
||||
}
|
||||
return nil, false
|
||||
|
||||
Reference in New Issue
Block a user