postgres-js failed to parse DATABASE_URL when the password contained URL-special characters (@ : / # ...). New createSqlClient(): uses DATABASE_URL if set, else falls back to PG* env vars (PGHOST/PGUSER/PGPASSWORD/...) which postgres-js reads directly — password passed verbatim, no URL encoding. docker-compose.prod.yml now sets PG* for the server instead of an inline DSN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
20 lines
576 B
TypeScript
20 lines
576 B
TypeScript
// Client Drizzle/PostgreSQL. Optionnel : sans DATABASE_URL, `db` vaut null et
|
|
// le jeu retombe sur la banque de questions en dur (dev sans infra).
|
|
|
|
import { drizzle } from "drizzle-orm/postgres-js"
|
|
import { createSqlClient } from "./client"
|
|
import * as schema from "./schema"
|
|
|
|
export type Database = ReturnType<typeof drizzle<typeof schema>>
|
|
|
|
function createDb(): Database | null {
|
|
const client = createSqlClient()
|
|
if (!client) {
|
|
return null
|
|
}
|
|
return drizzle(client, { schema })
|
|
}
|
|
|
|
export const db = createDb()
|
|
export const hasDb = db !== null
|
|
export { schema }
|