refactor: migrate from Neon serverless to node-postgres driver for Drizzle ORM

This commit is contained in:
javayhu 2025-02-23 01:06:25 +08:00
parent 3f66a24a60
commit ecaf761b61
4 changed files with 12 additions and 5 deletions

View File

@ -11,7 +11,6 @@
"dependencies": {
"@ai-sdk/openai": "^1.1.13",
"@hookform/resolvers": "^4.1.0",
"@neondatabase/serverless": "^0.10.4",
"@radix-ui/react-accordion": "^1.2.3",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-collapsible": "^1.1.3",

5
pnpm-lock.yaml generated
View File

@ -14,9 +14,6 @@ importers:
'@hookform/resolvers':
specifier: ^4.1.0
version: 4.1.0(react-hook-form@7.54.2(react@19.0.0))
'@neondatabase/serverless':
specifier: ^0.10.4
version: 0.10.4
'@radix-ui/react-accordion':
specifier: ^1.2.3
version: 1.2.3(@types/react-dom@19.0.3(@types/react@19.0.9))(@types/react@19.0.9)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)
@ -4299,6 +4296,7 @@ snapshots:
'@neondatabase/serverless@0.10.4':
dependencies:
'@types/pg': 8.11.6
optional: true
'@next/env@15.1.7': {}
@ -4969,6 +4967,7 @@ snapshots:
'@types/node': 20.17.19
pg-protocol: 1.7.1
pg-types: 4.0.2
optional: true
'@types/react-dom@19.0.3(@types/react@19.0.9)':
dependencies:

View File

@ -1,5 +1,11 @@
import { drizzle } from 'drizzle-orm/neon-http';
import { drizzle } from 'drizzle-orm/node-postgres';
/**
* https://orm.drizzle.team/docs/connect-overview
*
* Drizzle ORM runs SQL queries on your database via database drivers.
* Under the hood Drizzle will create a node-postgres driver instance.
*/
const db = drizzle(process.env.DATABASE_URL!);
export default db;

View File

@ -6,6 +6,9 @@ import { user, session, account, verification } from "@/db/schema";
export const auth = betterAuth({
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.
schema: {
user: user,
session: session,