Skip to content

Commit

Permalink
Validate same filters in duplicate indexes (#25931)
Browse files Browse the repository at this point in the history
Fixes #24968
  • Loading branch information
roji authored Sep 8, 2021
1 parent 289a9fc commit 1087a73
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ public static bool AreCompatible(
return false;
}

if (index.GetFilter() != duplicateIndex.GetFilter())
{
throw new InvalidOperationException(
RelationalStrings.DuplicateIndexFiltersMismatch(
index.Properties.Format(),
index.DeclaringEntityType.DisplayName(),
duplicateIndex.Properties.Format(),
duplicateIndex.DeclaringEntityType.DisplayName(),
index.DeclaringEntityType.GetSchemaQualifiedTableName(),
index.GetDatabaseName(storeObject),
index.GetFilter(),
duplicateIndex.GetFilter()));
}

return true;
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@
<data name="DuplicateIndexUniquenessMismatch" xml:space="preserve">
<value>The indexes {indexProperties1} on '{entityType1}' and {indexProperties2} on '{entityType2}' are both mapped to '{table}.{indexName}', but with different uniqueness configurations.</value>
</data>
<data name="DuplicateIndexFiltersMismatch" xml:space="preserve">
<value>The indexes {indexProperties1} on '{entityType1}' and {indexProperties2} on '{entityType2}' are both mapped to '{table}.{indexName}', but with different filters ('{filter1}' and '{filter2}').</value>
</data>
<data name="DuplicateKeyColumnMismatch" xml:space="preserve">
<value>The keys {keyProperties1} on '{entityType1}' and {keyProperties2} on '{entityType2}' are both mapped to '{table}.{keyName}', but with different columns ({columnNames1} and {columnNames2}).</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,23 @@ public virtual void Detects_duplicate_index_names_within_hierarchy_with_differen
modelBuilder);
}

[ConditionalFact]
public virtual void Detects_duplicate_index_names_within_hierarchy_with_different_filters()
{
var modelBuilder = CreateConventionalModelBuilder();
modelBuilder.Entity<Animal>();
modelBuilder.Entity<Cat>().HasIndex(c => c.Name).HasFilter("Foo").HasDatabaseName("IX_Animal_Name");
modelBuilder.Entity<Dog>().HasIndex(d => d.Name).HasFilter("Bar").HasDatabaseName("IX_Animal_Name");

VerifyError(
RelationalStrings.DuplicateIndexFiltersMismatch(
"{'" + nameof(Dog.Name) + "'}", nameof(Dog),
"{'" + nameof(Cat.Name) + "'}", nameof(Cat),
nameof(Animal), "IX_Animal_Name",
"Bar", "Foo"),
modelBuilder);
}

[ConditionalFact]
public virtual void Passes_for_incompatible_indexes_within_hierarchy_when_one_name_configured_explicitly()
{
Expand Down

0 comments on commit 1087a73

Please sign in to comment.