import { integer, pgTable, primaryKey, text, timestamp, } from "drizzle-orm/pg-core"; // users, accounts, sessions and verification_tokens are the tables the Auth.js // Drizzle adapter reads and writes. users also carries the sign-in record kept // by recordSignIn (src/db/users.ts). export const users = pgTable("users", { id: text("id") .primaryKey() .$defaultFn(() => crypto.randomUUID()), name: text("name"), email: text("email").unique().notNull(), emailVerified: timestamp("email_verified", { mode: "date" }), image: text("image"), createdAt: timestamp("created_at", { mode: "date", withTimezone: true }) .defaultNow() .notNull(), lastSignInAt: timestamp("last_sign_in_at", { mode: "date", withTimezone: true, }), signInCount: integer("sign_in_count").notNull().default(0), }); export const accounts = pgTable( "accounts", { userId: text("user_id") .notNull() .references(() => users.id, { onDelete: "cascade" }), type: text("type").notNull(), provider: text("provider").notNull(), providerAccountId: text("provider_account_id").notNull(), refresh_token: text("refresh_token"), access_token: text("access_token"), expires_at: integer("expires_at"), token_type: text("token_type"), scope: text("scope"), id_token: text("id_token"), session_state: text("session_state"), }, (account) => [ primaryKey({ columns: [account.provider, account.providerAccountId] }), ], ); export const sessions = pgTable("sessions", { sessionToken: text("session_token").primaryKey(), userId: text("user_id") .notNull() .references(() => users.id, { onDelete: "cascade" }), expires: timestamp("expires", { mode: "date" }).notNull(), }); export const verificationTokens = pgTable( "verification_tokens", { identifier: text("identifier").notNull(), token: text("token").notNull(), expires: timestamp("expires", { mode: "date" }).notNull(), }, (vt) => [primaryKey({ columns: [vt.identifier, vt.token] })], );