-
Notifications
You must be signed in to change notification settings - Fork 330
Add :constraint_handler and Ecto.Adapters.SQL.Constraint
#627
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
base: master
Are you sure you want to change the base?
Add :constraint_handler and Ecto.Adapters.SQL.Constraint
#627
Conversation
|
This is a proof of concept PR, from the original thread on the Google Group. I have not yet swapped the The main things I could use some insights and feedback on are:
All 4 of these items are somewhat interconnected, and affect the possible options of others. e.g. doing # 4 would be neat for allowing downstream libraries an escape hatch in case they structure their config differently, but it might make more sense to just put it in the As it is currently written, it should work for downstream libraries without breaking them, but it does not provide a clear path, primarily because I did not want to go down a particular direction without input. Let me know what you think 🙂 |
|
The mysql tests are reliant on an I can also just open a PR on |
| num = @base_migration + System.unique_integer([:positive]) | ||
| ExUnit.CaptureLog.capture_log(fn -> | ||
| :ok = up(PoolRepo, num, ConstraintMigration, log: false) | ||
| end) |
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.
other than moving this migration here, the other changes to this test are from mix format
|
I checked through the dependent libraries I could find from hex and I didn't really see many others that were sticking to the typical patterns from the built-in adapters, but maybe I just missed some. But I think if we just removed the EDIT: I don't know how I missed the SQLite adapter. They'd be affected probably |
|
Given it is a single function, can we make the contract a MFArgs instead of a module? This way we don't need to create new modules for every new adapter. We can just point to the existing function. Thank you. |
Don't worry I'm watching this 😈 |
d1c5bd2 to
4f80046
Compare
|
Ping! :) |
Pong 😬 I was trying to think of an example of when a custom constraint handler would be useful in Postgres, but most of the constraints I could think of could be handled by pg's existing "box" model for exclusion constraints, or they didn't feel like a realistic use-case. For now though, I think I'm just going to do a simple check that would otherwise be some business-logic you'd need to add to an update/insert, or use a Multi. If you can think of anything off the top of your head, let me know. |
defaults to existing adapter connection module
4f80046 to
d32d15e
Compare
- adds initial docs - updates behaviours and built-in connections
TODO
|
|
I'm stuck on the TDS test. Since we use Anyone have any ideas for how to test this? I haven't done TDS since 2015 in Ruby. I saw we could modify the |
|
My suggestion is to add a unit test, without focusing on the database, since the logic does not seem to be database specific, and then having a smoke test either via PG or MySQL would be fine. I also don't think we need a MFA or a behaviour, we could have |
|
Sounds good. My thought was that a module or mfargs was mainly so we could support compile-time config, similar to the I like the function idea, especially for ad-hoc use cases, but I think people who'd use this would still want compile-time support. The behaviour is really just for someone to be able to read the docs and see "oh I just need to implement [this] and have it fallback to the adapter's connection, then stick it in |
|
Our |
|
Ah, I missed I'll remove the behaviour and change stuff around to just expect a function |
Adds a new
:constraint_handlerto allow customizing adapter error handling, that can be passed as a shared option to repo functions, e.g.MyRepo.insert(..., constraint_handler: {MyCustomHandler, :to_constraints, []}), but also passed as repository config, similar to the:prefixoption.