feat(csms): add deployment script and database schema for user authentication

This commit is contained in:
2025-11-17 03:34:51 +08:00
parent 09c5ca1d3f
commit 86595c7639
21 changed files with 2377 additions and 16 deletions

24
apps/csms/src/lib/db.ts Normal file
View File

@@ -0,0 +1,24 @@
import { drizzle } from 'drizzle-orm/node-postgres'
import { Pool } from 'pg'
import * as schema from '@/db/schema.js'
let pgPoolInstance: Pool | null = null
let drizzleInstance: ReturnType<typeof drizzle> | null = null
export const useDrizzle = () => {
if (!pgPoolInstance || !drizzleInstance) {
pgPoolInstance = new Pool({
connectionString: process.env.DATABASE_CONNECTION_STRING,
})
drizzleInstance = drizzle({ client: pgPoolInstance, schema })
}
return drizzleInstance
}
export const closeDrizzle = () => {
if (pgPoolInstance) {
pgPoolInstance.end()
pgPoolInstance = null
drizzleInstance = null
}
}