Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate same filters in duplicate indexes #25931

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            if (index.GetFilter(storeObject) != duplicateIndex.GetFilter(storeObject))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/me goes and hides under a rock!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to skip filter configuration for the index on the dependent in table sharing, avoiding a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, will submit a fixup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
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