Repository navigation
fix(auth): carry Better Auth update hooks and defaults onto generated columns - #764
Merged
cpojer merged 2 commits intoNov 9, 2026
Merged
Conversation
… columns Direct Drizzle writes on auth tables skipped `onUpdate` and literal defaults, which Better Auth only applies on its own writes. Emit them as runtime-only modifiers so the DDL and existing migrations stay unchanged. Closes voidzero-dev#756 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cpojer
self-requested a review
November 9, 2026 22:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #756
Problem
Better Auth applies
onUpdateanddefaultValueitself on its own writes, but the Drizzle columns in.void/better-auth-schema.tshad neither. Writes that go directly through Drizzle missed them:db.update()on an auth table leftupdatedAtunchanged, and a row inserted withoutbannedstorednullinstead offalse.Changes
createColumnDefinitionnow emits:.$onUpdate(() => new Date())for Better Auth's built-inupdatedAtfields, unless overridden through additional fields or a plugin.$defaultFn(() => <literal>)for string, number and boolean defaults, on optional fields tooBoth are runtime-only Drizzle modifiers, so existing apps need no migration.
resolveFixedDefaultstill returns only required fields' defaults, somigrationSchemais unchanged.Custom update callbacks remain handled by Better Auth and are omitted from the generated Drizzle columns.
Function defaults such as
createdAt's() => new Date()are left out, as are date and JSON literals, matching the existing exclusions.Drizzle also runs
$onUpdateon insert when the value is omitted, and treats the column as optional in insert types. ForupdatedAtthis fills in the current time rather than failing theNOT NULLconstraint.Verification
packages/void/test/unit/auth-drizzle.test.tscover update hooks in all three dialects, required and optional literal defaults, excluded function/date/JSON defaults, and unchanged migration metadata.updatesetsupdatedAtand an insert gets the literal defaults.vp run checkpasses.vp test runlocally: 16,453 passed, 8 failed.api-webhookstimeouts that also fail onmainin a full run on this machine.cf-build-output(timeout) andplugin-cloudflare-v2(inspector portEADDRINUSE). These did not fail onmain, but passed 3 of 3 runs in isolation on this branch and do not reference the auth generator.🤖 Generated with Claude Code