Skip to content

Commit

Permalink
Don't scaffold default index method annotation
Browse files Browse the repository at this point in the history
When scaffolding, we have an Npgsql-specific IndexMethod annotation to
represent PostgreSQL's index methods. Previously, we would always
output this annotation on indices, even when the method was the
default (btree); NpgsqlAnnotationCodeGenerator would elide it as by-
convention.

Although this is cleaner, it caused issues whenever two indices where
defined on the same column:
dotnet/efcore#11846

We now scaffold the annotation only for non-default index methods as a
workaround; the issue should now affect much less people.

Fixes #228

(cherry picked from commit 38d2176)
  • Loading branch information
roji committed May 26, 2018
1 parent a38c6dd commit d768a5d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,14 @@ void GetIndexes()
}
}

index[NpgsqlAnnotationNames.IndexMethod] = reader.GetValueOrDefault<string>("amname");
// It's cleaner to always output the index method on the database model,
// even when it's btree (the default);
// NpgsqlAnnotationCodeGenerator can then omit it as by-convention.
// However, because of https://github.com/aspnet/EntityFrameworkCore/issues/11846 we omit
// the annotation from the model entirely.
var indexMethod = record.GetValueOrDefault<string>("amname");
if (indexMethod != "btree")
index[NpgsqlAnnotationNames.IndexMethod] = indexMethod;

table.Indexes.Add(index);
}
Expand Down

0 comments on commit d768a5d

Please sign in to comment.