ionztorm
ionztorm
DTDrizzle Team
Created by Raheel on 11/23/2024 in #help
0.36.0 - The third parameter in Drizzle ORM becomes an array
nope never give up! I think in this case we are using 2 packages that are both in beta, so the docs will alwayas be a little behind until full release
7 replies
DTDrizzle Team
Created by Raheel on 11/23/2024 in #help
0.36.0 - The third parameter in Drizzle ORM becomes an array
np I had the same problem about an hour ago 👍
7 replies
DTDrizzle Team
Created by Raheel on 11/23/2024 in #help
0.36.0 - The third parameter in Drizzle ORM becomes an array
you can find the PR here in the meantime: https://github.com/nextauthjs/next-auth/pull/12285
7 replies
DTDrizzle Team
Created by Raheel on 11/23/2024 in #help
0.36.0 - The third parameter in Drizzle ORM becomes an array
I have just submitted a PR to update the Auth JS docs for this. Here's my schema, there are a few edits: 1) in your index.ts i changed it to set the casing to snake case
export const db = drizzle({ connection: process.env.DATABASE_URL, casing: 'snake_case' });
export const db = drizzle({ connection: process.env.DATABASE_URL, casing: 'snake_case' });
2) in your drizzle.config.ts i did the same
export default defineConfig({
schema: './src/db/schema',
out: './src/db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: env.DATABASE_URL,
},
casing: 'snake_case',
});
export default defineConfig({
schema: './src/db/schema',
out: './src/db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: env.DATABASE_URL,
},
casing: 'snake_case',
});
3) authjs schema: You no longer need to pass in names for the fields:
'drizzle-orm';
import {
type AnyPgColumn,
boolean,
integer,
pgTable,
primaryKey,
text,
timestamp,
} from 'drizzle-orm/pg-core';
import type { AdapterAccountType } from 'next-auth/adapters';

export const users = pgTable('user', {
id: text()
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
name: text(),
email: text().unique(),
emailVerified: timestamp({ mode: 'date' }),
password: text(),
image: text(),
});

export const accounts = pgTable(
'account',
{
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
type: text().$type<AdapterAccountType>().notNull(),
provider: text().notNull(),
providerAccountId: text().notNull(),
refresh_token: text(),
access_token: text(),
expires_at: integer(),
token_type: text(),
scope: text(),
id_token: text(),
session_state: text(),
},
(account) => [
primaryKey({
columns: [account.provider, account.providerAccountId], // Specify columns as an array.
name: 'provider_providerAccountId_pk', // Optional: name for the primary key.
}),
],
);

export const sessions = pgTable('session', {
sessionToken: text().primaryKey(),
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
expires: timestamp({ mode: 'date' }).notNull(),
});

export const verificationTokens = pgTable(
'verificationToken',
{
identifier: text().notNull(),
token: text().notNull(),
expires: timestamp({ mode: 'date' }).notNull(),
},
(verificationToken) => [
primaryKey({
columns: [verificationToken.identifier, verificationToken.token],
}),
],
);

export const authenticators = pgTable(
'authenticator',
{
credentialID: text().notNull().unique(),
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
providerAccountId: text().notNull(),
credentialPublicKey: text().notNull(),
counter: integer().notNull(),
credentialDeviceType: text().notNull(),
credentialBackedUp: boolean().notNull(),
transports: text(),
},
(authenticator) => [
primaryKey({
columns: [authenticator.userId, authenticator.credentialID],
}),
],
);
'drizzle-orm';
import {
type AnyPgColumn,
boolean,
integer,
pgTable,
primaryKey,
text,
timestamp,
} from 'drizzle-orm/pg-core';
import type { AdapterAccountType } from 'next-auth/adapters';

export const users = pgTable('user', {
id: text()
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
name: text(),
email: text().unique(),
emailVerified: timestamp({ mode: 'date' }),
password: text(),
image: text(),
});

export const accounts = pgTable(
'account',
{
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
type: text().$type<AdapterAccountType>().notNull(),
provider: text().notNull(),
providerAccountId: text().notNull(),
refresh_token: text(),
access_token: text(),
expires_at: integer(),
token_type: text(),
scope: text(),
id_token: text(),
session_state: text(),
},
(account) => [
primaryKey({
columns: [account.provider, account.providerAccountId], // Specify columns as an array.
name: 'provider_providerAccountId_pk', // Optional: name for the primary key.
}),
],
);

export const sessions = pgTable('session', {
sessionToken: text().primaryKey(),
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
expires: timestamp({ mode: 'date' }).notNull(),
});

export const verificationTokens = pgTable(
'verificationToken',
{
identifier: text().notNull(),
token: text().notNull(),
expires: timestamp({ mode: 'date' }).notNull(),
},
(verificationToken) => [
primaryKey({
columns: [verificationToken.identifier, verificationToken.token],
}),
],
);

export const authenticators = pgTable(
'authenticator',
{
credentialID: text().notNull().unique(),
userId: text()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
providerAccountId: text().notNull(),
credentialPublicKey: text().notNull(),
counter: integer().notNull(),
credentialDeviceType: text().notNull(),
credentialBackedUp: boolean().notNull(),
transports: text(),
},
(authenticator) => [
primaryKey({
columns: [authenticator.userId, authenticator.credentialID],
}),
],
);
7 replies
DTDrizzle Team
Created by ionztorm on 11/23/2024 in #help
Enum Type Creation
well, it just randomly has started working. There's still no enum type definition in the sql migration file but the migrate worked and if I create a record in the dashboard, the role is limited to the enum options! weird! I changed nothing. I'll go sit in a corner and rock back and forth for a bit.
2 replies