(Next)Auth.js Drizzle Schema
See https://authjs.dev/getting-started/adapters/drizzle#schemas for the Drizzle Schema provided
I haven't been able to figure out how to get Auth.js schema working with drizzle. I believe the issue is handling the composite primary key
In the example, the accounts, verificationTokens, authenticators primaryKeys are respectively
Does the property name of the primary key matter? In my old drizzle schema, it looked like it was named
compoundKey
, while the current documentation uses either pk
or pkWithCustomName
and the auth.js example is compoundKey
, compositePk
, and compositePK
(is this one a typo?).
I can run drizzle-kit generate
and drizzle-kit migrate
, while when running drizzle-kit push
gives me this error:
Sorry if this doesn't make any sense, let me know if I can provide more information
Using node-postgress and pg driver, not sure if that mattersAuth.js | Drizzle
Authentication for the Web
![No description](https://cdn.answeroverflow.com/1248889656876077056/image.png)
![No description](https://cdn.answeroverflow.com/1248889657156960297/image.png)
8 Replies
drizzle-kit check gets me Everything's fine πΆπ₯ and this is what drizzle-kit introspect gets me (images above)
i love u guys ur twt once qrtd me
also fyi the next authjs documentation still uses the old migrator script for migration instead of the drizzle-kit migrate command
Pastebin
import { boolean, integer, pgTable, primaryKey, text, timesta...
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.
my schema.ts also if that is helpful
tho its essentially a carbon copy of what auth.js recommends except i just changed all the composite primary keys property names to pk
i figured it out (deleted the table and migrated again and pushed again and it worked :love:)
it appears i have spoken too soon
i am still not certain why it is doing this:
[β] Pulling schema from database...error: constraint "authenticator_userid_credentialid_pk" of relation "authenticator" does not exist
at /Users/jeremy/Github/defraud/node_modules/.pnpm/drizzle-kit@0.22.5/node_modules/drizzle-kit/bin.cjs:77694:15
![No description](https://cdn.answeroverflow.com/1249116379374682122/image.png)
fyi the verbose output:
![No description](https://cdn.answeroverflow.com/1249122786442743859/image.png)
Anyway, I think I have actually figured it out, the following code works and is able to be pushed fine:
Notice the order of the columns [credentiald, userId]. I imagine the property name of the object (in this case,
pk
, but in the Auth.js schema compositePK
) doesn't matter, but for some reason, the order of the columns makes a difference.
Here are the results for different variations of the above after deleting the table authenticators
and then running drizzle-kit push
:
I suspect this is the related issue, but not certain:
https://github.com/drizzle-team/drizzle-orm/issues/2326
GitHub
[BUG]: drizzle-kit does not respect the order of columns configured...
What version of drizzle-orm are you using? 0.30.10 What version of drizzle-kit are you using? 0.21.1 Describe the Bug export const worksToCreators = sqliteTable( 'works_to_creators', { work...
My guess is that the column order of the primary key when using
drizzle-kit generate
is as given, while when using drizzle-kit push
, it is ordered alphabetically?
Actually, I am not certain of the above anymore.
When the table looks like this:
Running drizzle-kit generate
outputs the following SQL statement,
and running drizzle-kit push
executes the following statement
which is the same. Yet, running drizzle-kit push
again reutrns this:
I am a bit confused at what's going on.
Note on the database side the index authenticator_userId_credentialID_pk
does exist with
Also I am on version
drizzle-kit: v0.22.6
drizzle-orm: v0.31.2