-
Notifications
You must be signed in to change notification settings - Fork 225
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
Update range mapping for schema-qualified and quoted ranges #626
Conversation
e260ae6
to
0e9d946
Compare
0e9d946
to
ea6ab0e
Compare
acec2d1
to
496b150
Compare
a0e8b25
to
e7e777c
Compare
This should follow #672 for changes in the NodaTime plugin. |
e7e777c
to
2c2326a
Compare
00641a2
to
e142aed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address my comment. Otherwise, LGTM.
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlRangeTypeMapping.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally had some time to review stuff...
Apart from the specific comments, I'm not too enthusiastic about including the delimiters in the store type - in previous work I tried to keep the StoreType clean, and add the delimiters only as needed when generating migrations SQL. This was the previous logic when creating managing enums, which you changed in #605. The new logic creates an odd discrepancy between the tables/sequences/indices (which have separate schema and name) and enums/ranges (which don't, and therefore have the schema packed and delimited into the name). Of course, if we want to support enums/ranges in non-default schemas we don't have much choice - EF Core has no concept of a type's schema, and treats a store type as a single string (e.g. in AddColumnOperation, RelationalTypeMapping) so have to delimit and pack the type's schema and name into a single string StoreType.
We may want to raise this with the EF Core people - it may make sense for them to add type schemas where necessary in the core, obviating the current logic. Since enums/ranges in user-defined schemas seem pretty rare, I'd at least want to hear their opinion before implementing this new logic (which has already been merged for enums). I think it wouldn't be so bad for enums/ranges in user-defined schemas to not be supported before EF Core 3.0, if it means we get it right.
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlRangeTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlRangeTypeMapping.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG.NodaTime/Storage/Internal/NpgsqlNodaTimeTypeMappingSourcePlugin.cs
Outdated
Show resolved
Hide resolved
src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Outdated
Show resolved
Hide resolved
77f133f
to
227ea85
Compare
2d495f1
to
b3cca03
Compare
@roji Updated to address your review. I've also opened #685 as a follow-up to #605 based on your review.
Agreed. I'll open an issue and link back to this.
I can't speak to rarity in general...but I do work frequently with databases that have schema-qualified enums, so the previous logic was a real headache in day-to-day usage. I would be happy to see this logic be reimplemented upstream so that enums/ranges behave more like tables/indexes/etc, but I don't think that means we need to wait for the |
b3cca03
to
077d561
Compare
While putting together #626 I found that an One possible fix is to do something like this (included here in 077d561): protected override void Generate(
AlterDatabaseOperation operation,
IModel model,
MigrationCommandListBuilder builder)
{
Check.NotNull(operation, nameof(operation));
Check.NotNull(builder, nameof(builder));
// Alter operations may not have a default schema attached. If not, try to attach one for schema-qualified types.
if (operation[RelationalAnnotationNames.DefaultSchema] == null)
operation[RelationalAnnotationNames.DefaultSchema] = model[RelationalAnnotationNames.DefaultSchema];
GenerateEnumStatements(operation, model, builder);
GenerateRangeStatements(operation, model, builder);
foreach (var extension in PostgresExtension.GetPostgresExtensions(operation))
GenerateCreateExtension(extension, model, builder);
builder.EndCommand();
} This is needed because of the way we store enum/range annotations. Thus in the current implementation (i.e. here in this PR),
edit: I played around with a couple of alternatives (e.g. storing an annotation whose value is a collection of |
fc3f677
to
0e6e82e
Compare
Updated for the changes from #698. Ready for another review, @roji @YohDeadfall. |
- Properly quote schema and type name - Respect default schema annotation - Follows PR 605 (schema-scoped enums)
0e6e82e
to
e11a133
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Please check out the nits and possibly unneeded DefaultSchema annotation on the migration operation before merging.
Let's prioritize this to make sure it makes it into 2.2.
src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Outdated
Show resolved
Hide resolved
@roji Thanks for the re-review. I've updated accordingly. The one questionable change is the XML doc referring to the default schema, I put in some language, but not sure if it was what you meant. Could you give that another quick look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes. Look at my two minor comments, otherwise LGTM!
src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Outdated
Show resolved
Hide resolved
In #626, ISqlGenerationHelper was added as a dependency of NpgsqlTypeMappingSource, to maintain DI practices and allow users to inject their own version if needed. However, NpgsqlDesignTimeServices wasn't updated with the new dependency, so all design-time operations started failing (e.g. create migrations).
@austindrenski this PR broke design-time operations, see ad4e0d6 for the fix. |
Oh yikes.....sorry about that. Thanks for fixing it! |
No problem :) It's a bit troubling to not have end-to-end testing to catch this kind of thing - we're not perfect yet :) |
Changes
.ForNpgsqlHasRange(...)
, then use the default schema annotation.StoreType
).