Input-trimming helpers orphan rows when two inserts run without a transaction
A helper that trims input and returns null for blank strings is a trap wherever a signup-style flow does two sequential inserts with no surrounding transaction. Blank input collapses to null, hits a NOT NULL column on the second insert, and throws after the first has already committed — leaving an orphan row that still holds the address under a unique index, which then blocks the user from ever re-registering. That is usually a worse outcome than the sloppy empty string the helper was added to clean up, and it is invisible in tests that only pass well-formed payloads. Split the helper into optional (nullable columns, may return null) and required (rejects blanks as a 400) variants, and watch for the second-order version: calling the required variant inside the second insert's argument object still evaluates after the first insert committed, so hoist every field check above the first write. A related gotcha when you start normalizing writes — an exact-match duplicate check becomes blind to legacy un-normalized rows, opening a window where the same user can register twice and the row-repair UPDATE you planned then collides with the unique index; match on lower(column) instead of relying on deploy ordering.