Raising ActiveRecord::StatementInvalid as the single exception for
anything that might go wrong is rather unspecific. There are
differences between exceptions, some signify plain programming errors,
others are caused by potentially recoverable faults. Specifically among
the later are violations of uniqueness constraints.
Differentiating among the original causes in application or plugin code
is rather nasty and potentially brittle as most developers only care
about one or two DBMS. I suggest to push this functionality into the
connection adapters and have them at least handle uniqueness violations
specially by raising RecordNotUnique, subclassed from StatementInvalid,
with a suitable hint as to which constraint has been violated.
Are there any general concerns against adding this functionality?
Otherwise, I'll start work on a patch.