Drizzle Postgres UUID
How can I force better-auth to use uuid's for id's and rely on the database to generate them with the drizzle adapter. The below doesn't seem to work.
This PR merged seems it got rid of the behavior? https://github.com/better-auth/better-auth/pull/2248
13 Replies
Previously in an older PR, I changed schema generation to use
uuid
over text
.
However this was a major breaking change for all users who previously used our schema generation - a mistake on my end.
If they had an existing schema which used id
s as text
(which has been what we've always been using until my breaking PR) then using schema generation after my breaking-pr would cause all id
fields to convert to uuid
. Because of this, their schema's can't be pushed since text
can't convert to uuid
.
Right now, there isn't a way for you to tell the schema generation to use uuid
for id
fields.
You will have to manually replace each id
field to use uuid
.Thank you for the info!
One more question, the better-auth schema is overwriting my drizzle schema everytime and reverting any changes I make too it. Is that expected or is it supposed to merge in changes?
It prompts you if you want to overwrite.
There isn't merging functionality as of now.
@Ping I don't really understand, I changed the id's from text to uuid in my schema's manually, but I still get:
Are you on the latest better-auth?
Yeah I just installed it
Can you enable debugLogs in your adapter options?
Yeah I'll try it later, I just went out to buy some beer, sorry
So it complains about the id column, since the postgres error mentions $1
Can I see your auth config?
Pastebin
Pastebin.com - Burn After Read paste
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
You can discard the onQuery and generateState, that was some testing stuff I was trying out
First of all, can you remove the
usePlural: true,
part of your code? It's redundent (and possibly can cause errors) if you define the schema yourself.
And right next to where you had usePlural
, please add debugLogs: true,
to enable debug logs.
Then go through your auth flow which had the error, and show me what the debug logs print in your console.
@JROCBABYOkay I will, as soon as I get home, thanks for the help 🙏🏻
https://pastebin.com/bQVgzjBE @Ping
I removed usePlural and added the debugLogs
I'm trying to use OAuth github, since this worked before before I migrated from next auth v5.
So what happens is,
BetterAuth’s Drizzle adapter is adding a non-UUID id field (5RhgXVViWPC8GTxxxxxxxxxxxxxxxxxx) to the verifications insert, expecting id to be text (per its older schema), but my verifications.id is uuid. The override attempt failed because BetterAuth’s internal logic or adapter is bypassing the custom createVerification method. The error is specific to verifications.id, and other ID-like fields (credentialId, etc.) are unaffected, as they’re correctly text and not involved in the OAuth verification step.
Ah it was the generateIds options, I set that to false and everything works like a charm now