Hello folks!
This proposal is about adding a mechanism for users of ecto_sql to be able to handle custom "uncalled" exceptions in the adapter with the `to_constraints` callback. This would allow for things such as MyXQL and the matching adapter to be able to opt-in to support handling check constraint exceptions.
Background:
I was recently working on a feature to add a non-overlapping date range constraint in MySQL, which resulted in me basically using a trigger to return a `signal` of `ER_DUP_ENTRY` if there was an existing overlap. I would've preferred a custom SQLSTATE/error but it was close enough. You can see the thread and code on the elixirforum if you're interested (
https://elixirforum.com/t/handling-a-custom-sql-signal-similar-to-changeset-constraint-functions/64303)
That got me thinking though, and remembered that we recently had to add some custom SQL in a migration to support a table check constraint in our MySQL database.
MyXQL has `:extra_error_codes` as a way to handle them at that layer, but I noticed that there's no way to handle them higher in `ecto_sql`
So I'd like to propose a way that we could configure at compile-time an error handler mfa that could allow extension of the `Ecto.Adapters.SQL.Connection` `to_constraint` callback.
To me this would be the ideal place to accommodate new error handling features into the adapters without having to convince people to try RCs, as presumably they'd have already built the new handler themselves, we'd just be bringing it into the adapters.
It doesn't "seem" like it would be particularly difficult to implement (and I'm happy to take a pass at it) but I'd like to know people's appetite for this, and what people think the right interface would be. I'm aware they are behaviours but as the adapter and the connection are both behaviours it seems like it would be difficult to inject a wrapper connection module from config.
Let me know what people think, and thank you for your time reading my rambling :D