dialect/sql/schema: properly handle indexes of tables with uncountable name (#828)

This commit is contained in:
Ariel Mashraki
2020-10-08 23:24:54 +03:00
committed by GitHub
parent 064c25609b
commit 13b379d07c
24 changed files with 2715 additions and 25 deletions

View File

@@ -189,8 +189,10 @@ func (d *Postgres) indexes(ctx context.Context, tx dialect.Tx, table string) (In
if err := rows.Scan(&name, &column, &primary, &unique, &seqindex); err != nil {
return nil, fmt.Errorf("scanning index description: %v", err)
}
// If the index is prefixed with the table, it's probably was
// added by `addIndex` (and not entc) and it should be trimmed.
// If the index is prefixed with the table, it may was added by
// `addIndex` and it should be trimmed. But, since entc prefixes
// all indexes with schema-type, for uncountable types (like, media
// or equipment) this isn't correct, and we fallback for the real-name.
short := strings.TrimPrefix(name, table+"_")
idx, ok := names[short]
if !ok {