feat(db): Drizzle DAL with withUser/asAdmin GUC wrapper (Phase 2)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import 'server-only'
|
||||
import { Pool } from 'pg'
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import * as schema from './schema'
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
throw new Error('DATABASE_URL not configured')
|
||||
}
|
||||
if (!process.env.DATABASE_URL_ADMIN) {
|
||||
throw new Error('DATABASE_URL_ADMIN not configured')
|
||||
}
|
||||
|
||||
// app_user pool: RLS enforced. Used for all normal user operations.
|
||||
const userPool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
max: 10,
|
||||
})
|
||||
|
||||
// app_admin pool: BYPASSRLS. Used for admin user CRUD and service operations.
|
||||
const adminPool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL_ADMIN,
|
||||
max: 5,
|
||||
})
|
||||
|
||||
export const userDb = drizzle(userPool, { schema })
|
||||
export const adminDb = drizzle(adminPool, { schema })
|
||||
|
||||
export type UserDb = typeof userDb
|
||||
export type AdminDb = typeof adminDb
|
||||
Reference in New Issue
Block a user