-
Notifications
You must be signed in to change notification settings - Fork 230
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
Feature - Use enum to pick index method #890
Comments
Something like this
** Names subject to change. |
There are already various other places where PostgreSQL lists of values are specified as strings - notably types (e.g. when users specify In general it seems preferable for users to consult the PostgreSQL documentation to know these values - at the very least we should point them towards the right page from the xmldocs. |
See https://stackoverflow.com/questions/56207300/does-npgsql-expose-a-strongly-typed-list-of-postgresql-column-types/56207864#56207864 for a similar request for PostgreSQL types. |
First of all, I have to start by saying I appreciate the work you've done so far. This provider is better than most out there. I did consider all that, this is not meant to be a replacement but an overload. Similar to how model builders accept both a property expression and string property name as a selector. I also didn't intend for it as a discovery mechanism for index types. I meant it for type safety. The cost of a misspelled enum is a squiggly line and build failure, the cost of a misspelled string literal is a run-time error when the model lazy loads on the first GET request after the build, startup and service activation time. Requiring a minimum of another refactor-build-execute cycle to correct a silly spelling error. I do understand the cost vs benefit is low. It's a cherry on top, not the cake. There's already so many features missing in EF Core and it's providers, I'm sure nobody would notice a delayed enum update if there has to be any. In the answer to the SO question, you've said that they are well established names that never change, so there will hardly be any updates leading to refactor. Maybe it's not that much effort after all? It certainly takes less time to code a solution for this than to have this debate. There's no rule saying that you have to turn each and every string accepting method into an enumeration. A list of 6 index types that are unlikely to change sounds like the ideal candidate. In addition to providing a link to the documentation, the xmldocs can say that "this list is not exhaustive, use the string overload for unlisted types." as a way for you to limit your liability. With the postgres extension system it is technically impossible to build an exhaustive list of types and indexes anyway. There is no need for 100% parity, it's not like 100% of pg features are exposed in this provider already. Even with the gazillion column types, I don't see the harm in having an enumeration, although, it would be hell of a lot easier if C# supported string enums. If you have a table in the docs indicating the type mapping, why can't you have an enum and have the enum generate the table in the docs? Saying that it's okay to use strings is not an argument against static types, it simply means that it's okay to use strings, which is fine and is not being brought into question. Static types are consistent, compatible with intellisense and provide build time errors as opposed to run-time errors. None of these are done by strings. TLDR: Wrap index types as they are only few and require no maintenance I have far more important questions for you,
I'm reading through your source now, I don't see why you can't add a PropertyAnnotation called "Check" that accepts a predicate as a lambda expression. And in the sql generator create an You could also add an IndexAnnotation called You could be thinking that migrations allow for all this with arbitrary sql execution but migrations are a state transition. Migrations are tied to a specific db. They update the db from one state to the next. They are not a definition. There should be a stateless single source of truth to the database model in order for the code to be readable, portable and maintainable and this has to come in the form of feature completeness from the provider. |
Those are fair points, but I think this conversation turns on the cost/benefit you mentioned above. There's a lot of work to be done, and every feature costs time to develop and adds to the long term maintenance burden. PRs from new contributors help with the first part, but there's still the question of whether it adds enough value to make sense as part of this project (as compared to being an extension method in your specific project).
I can answer a few of these off-hand, but to keep this thread on topic, please open new issues for further discussion on them
Blocked upstream, tracking via #837.
This should already be implemented by the upstream project, no?
We recommend seeding data with negative key values. Otherwise you should add the requisite raw SQL to bring your sequence up to date. See #536, #573, #759.
Our docs are a always a work in progress that could certainly use more attention. PRs are always welcome :)
Feature completeness is always going to be a high bar when considering a backend as feature-rich as PostgreSQL. More contributors would certainly help, and new contributors are always welcome! |
@austindrenski thanks for the good responses above, here's some more from me.
Thanks for saying that! That's also good to hear. On the issue of index method enums, it's worth saying I'm not totally against the idea. However:
On the specific questions, to supplement @austindrenski's responses:
This has actually been unblocked at the EF Core side, I'm not actually sure we need to do anything to make it work in Npgsql (but obviously testing is needed).
The HiLo feature seems to be very rarely used (not just with PostgreSQL, but in general in EF Core), and this is the first time anyone has raised the lack of support for specifying the starting value. See my comment at the bottom about eagerly implementing features without a clear need, but if you'd like you can open an issue for this.
This is tracked by #819 and will hopefully make it into 3.0.0.
I'm not sure I understand the question - is this a general EF Core question on how EnsureCreated() interacts with migrations? It doesn't seem to be specific to the Npgsql provider.
Very much agree - our docs could definitely use some work. It's not always easy to keep them in sync with actual features, and it's possibly a good place for contributors to start as they're exploring/discovering the provider.
Agree as well - the range of features is potentially extremely large, and you can see the same issue in Microsoft-developed providers as well (e.g. SQL Server / Sqlite). In some cases we are also limited by upstream EF Core, but in general this is an open source project maintained by the community. As a general rule, I personally try to avoid rushing into feature implementation without users asking for them, or without a plausible reason to believe it would be useful. In this project it's very easy to fall into the trap of eagerly implementing tons of features and translations with the goal of being feature-complete (and because it's fun/interesting), but which almost nobody will use, and which we then have to maintain. So while it may sound odd, I'd say feature-completeness isn't exactly an explicit goal. If you see anything you're interested in it would definitely be great to have you (and anyone else) as a contributor! |
It would be nice to have an overload of
that accepts an enum value. Primarily for intellisensability. (I would do this, if approved)
The text was updated successfully, but these errors were encountered: