chore: optimize db instance init with schema

This commit is contained in:
javayhu 2025-06-12 00:20:06 +08:00
parent 563fc2099a
commit a7c56f4a6c
2 changed files with 2 additions and 12 deletions

View File

@ -4,6 +4,7 @@
*/
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
@ -12,7 +13,7 @@ if (!connectionString) {
// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(connectionString, { prepare: false });
const db = drizzle(client);
const db = drizzle(client, { schema });
/**
* Connect to Neon Database

View File

@ -1,6 +1,5 @@
import { websiteConfig } from '@/config/website';
import db from '@/db/index';
import { account, session, user, verification } from '@/db/schema';
import { defaultMessages } from '@/i18n/messages';
import { LOCALE_COOKIE_NAME, routing } from '@/i18n/routing';
import { sendEmail } from '@/mail';
@ -24,16 +23,6 @@ export const auth = betterAuth({
appName: defaultMessages.Metadata.name,
database: drizzleAdapter(db, {
provider: 'pg', // or "mysql", "sqlite"
// The schema object that defines the tables and fields
// [BetterAuthError]: [# Drizzle Adapter]: The model "verification" was not found in the schema object.
// Please pass the schema directly to the adapter options.
// https://www.better-auth.com/docs/adapters/drizzle#additional-information
schema: {
user: user,
session: session,
account: account,
verification: verification,
},
}),
session: {
// https://www.better-auth.com/docs/concepts/session-management#cookie-cache