Commit Graph
3 Commits
Author SHA1 Message Date
Waleed 440a68bff9 improvement(audits): skip the sql-date-binding parse for files without drizzle-orm (#6554)
check:sql-date-binding Babel-parsed all 13,941 source files in apps, packages,
and scripts. A violation can only come from an `sql` tag resolved through a
`drizzle-orm` import, and both the static and dynamic resolvers match the
specifier as a string literal, so a file that never names the module cannot
produce one. Only ~590 files do.

Skipping the parse for the other 92% of bytes takes the audit from ~4.5s to
~0.8s and drops it out of the four slowest audits, taking check:audits from
6.0s to 5.3s wall and 38.0s to 32.9s serial. Output is unchanged.
2026-08-11 12:11:13 -07:00
Waleed 8c49d35a9c fix(scripts): make the sql Date-binding audit precise and crash-proof (#6340)
* fix(scripts): make the sql Date-binding audit precise and crash-proof

Resolve the drizzle `sql` tag from its import binding, scope Date bindings
lexically, tolerate unparseable files, accept the allow annotation above a
multi-line template, and scan the root scripts directory.

* fix(scripts): honor shadowed bindings and defaulted destructured Dates

* fix(scripts): audit drizzle sql tags bound through a dynamic import

* chore(scripts): drop the sql Date-binding unit tests and the exports that served them

* chore(scripts): drop the script unit tests and the exports that served them
2026-08-06 14:30:58 -07:00
Waleed 2ba455647b fix(db): bind every raw-sql Date through its column encoder (#6337)
* fix(db): bind every raw-sql Date through its column encoder

`drizzle()` overwrites postgres-js's temporal serializers (OIDs 1082/1083/
1114/1184/1182/1185/1115/1231) with an identity function because drizzle maps
timestamps itself through the column's `mapToDriverValue`. A raw `sql` template
carries no column context, so an interpolated `Date` skips that mapping, reaches
the identity serializer unchanged, and the wire encoder throws
`ERR_INVALID_ARG_TYPE`. The pools' `prepare` / `fetch_types` options are
irrelevant: the serializer swap happens for all four combinations.

Five live sites still interpolated a bare `Date`, the stale schedule-job filter
among them — it has no try/catch, so a database async backend would surface a
500 from the schedule tick. Bind each cutoff with `sql.param(date, column)`.

The testing `sql` mock's guard cannot see untested code or the tests that
override the drizzle-orm mock, so add `check:sql-date-binding`: a Babel-AST
audit over apps/** and packages/** that resolves Date-valued bindings per file
and rejects any that reach a raw template unbound. Correct the mock's comment,
which attributed the failure to postgres-js under `fetch_types: false`.

* fix(scripts): require the documented sql-date-bound annotation form and a reason
2026-08-06 12:16:27 -07:00