-
Notifications
You must be signed in to change notification settings - Fork 256
Add support for INCLUDE clause in indexes #699
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
Changes from all commits
e967fda
1da5630
6eda95c
81ccc5c
53bdc8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,8 +112,7 @@ protected override void Generate( | |
| } | ||
|
|
||
| // Comment on the table | ||
| var comment = operation[NpgsqlAnnotationNames.Comment] as string; | ||
| if (comment != null) | ||
| if (operation[NpgsqlAnnotationNames.Comment] is string comment && comment.Length > 0) | ||
| { | ||
| builder.AppendLine(';'); | ||
|
|
||
|
|
@@ -245,8 +244,7 @@ protected override void Generate( | |
|
|
||
| base.Generate(operation, model, builder, terminate: false); | ||
|
|
||
| var comment = operation[NpgsqlAnnotationNames.Comment] as string; | ||
| if (comment != null) | ||
| if (operation[NpgsqlAnnotationNames.Comment] is string comment && comment.Length > 0) | ||
| { | ||
| builder.AppendLine(';'); | ||
|
|
||
|
|
@@ -535,9 +533,6 @@ protected override void Generate( | |
| Check.NotNull(operation, nameof(operation)); | ||
| Check.NotNull(builder, nameof(builder)); | ||
|
|
||
| var method = (string)operation[NpgsqlAnnotationNames.IndexMethod]; | ||
| var operators = (string[])operation[NpgsqlAnnotationNames.IndexOperators]; | ||
|
|
||
| builder.Append("CREATE "); | ||
|
|
||
| if (operation.IsUnique) | ||
|
|
@@ -551,30 +546,40 @@ protected override void Generate( | |
| .Append(" ON ") | ||
| .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)); | ||
|
|
||
| if (method != null) | ||
| if (operation[NpgsqlAnnotationNames.IndexMethod] is string method && method.Length > 0) | ||
| { | ||
| builder | ||
| .Append(" USING ") | ||
| .Append(method); | ||
| } | ||
|
|
||
| var operators = operation[NpgsqlAnnotationNames.IndexOperators] as string[]; | ||
|
|
||
| builder | ||
| .Append(" (") | ||
| .Append(IndexColumnList(operation.Columns, operators)) | ||
| .Append(")"); | ||
|
|
||
| if (!string.IsNullOrEmpty(operation.Filter)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roji hi, I don't know why this 'Where' is deleted but i can't add a filter for my all indexes. I need to add this index filter; 'is_deleted is FALSE' just because i am using soft delete with unique indexes. Any idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /CC: @khellang
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @suadev It's deleted because it's using the overriden If you take a look at the base class (in EF Core), you can see that it's still adding the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add to what @YohDeadfall wrote, the WHERE support wasn't deleted - it was simply moved into EF Core itself (see MigrationsSqlGenerator). Are you seeing an actual issue with it not working? If so, please open a new issue with a code sample so we can investigate.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may need to look at this: https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext#design-time-dbcontext-configuration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roji thanks, but i didn't get it. I am still not sure what is my mistake. Overriding IndexOptions method is not a correct way?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also try to just modify the model itself, instead of swapping components? I.e. protected override void OnModelCreating(ModelBuilder modelBuilder) {
foreach (var entity in modelBuilder.Model.GetEntityTypes()) {
foreach (var index in entity.GetDeclaredIndexes()) {
if (index.IsUnique) {
index.SetFilter("is_deleted is FALSE");
}
}
}
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @khellang thank you! i am not even aware of GetDeclaredIndexes() method !
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the model is definitely a better approach than replacing services, wherever it's possible. |
||
| { | ||
| builder | ||
| .Append(" WHERE ") | ||
| .Append(operation.Filter); | ||
| } | ||
| IndexOptions(operation, model, builder); | ||
|
|
||
| builder.AppendLine(';'); | ||
|
|
||
| EndStatement(builder); | ||
| } | ||
|
|
||
| protected override void IndexOptions(CreateIndexOperation operation, IModel model, MigrationCommandListBuilder builder) | ||
| { | ||
| if (operation[NpgsqlAnnotationNames.IndexInclude] is string[] includeProperties && includeProperties.Length > 0) | ||
| { | ||
| builder | ||
| .Append(" INCLUDE (") | ||
| .Append(ColumnList(includeProperties)) | ||
| .Append(")"); | ||
| } | ||
|
|
||
| base.IndexOptions(operation, model, builder); | ||
|
roji marked this conversation as resolved.
|
||
| } | ||
|
|
||
| protected override void Generate(EnsureSchemaOperation operation, [CanBeNull] IModel model, MigrationCommandListBuilder builder) | ||
| { | ||
| Check.NotNull(operation, nameof(operation)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.