-
Notifications
You must be signed in to change notification settings - Fork 108
Inconsistent config of database setup connection url #744
Description
Describe the bug
In the docs there is the following seciont of "advanced configuration" that shows the option to include a custom connection string
export default defineNuxtConfig({
hub: {
db: {
dialect: 'postgresql',
driver: 'postgres-js', // Optional: explicitly choose driver
connection: {
connectionString: process.env.DATABASE_URL
}
}
}
})But connection.connectionString is only used for neon. Everywhere else, db/setup.ts looks for connection.url
connection.url:
Lines 69 to 75 in 7d6122b
| config.connection = defu(config.connection, { url: process.env.POSTGRES_URL || process.env.POSTGRESQL_URL || process.env.DATABASE_URL || '' }) | |
| if (config.driver && ['neon-http', 'postgres-js'].includes(config.driver) && !config.connection.url) { | |
| throw new Error(`\`${config.driver}\` driver requires \`DATABASE_URL\`, \`POSTGRES_URL\`, or \`POSTGRESQL_URL\` environment variable`) | |
| } | |
| if (config.connection.url) { | |
| config.driver ||= 'postgres-js' | |
| break |
Lines 317 to 319 in 7d6122b
| const client = postgres('${connection.url}', { | |
| onnotice: () => {} | |
| }) |
connection.connectionString for neon:
Line 329 in 7d6122b
| const sql = neon(${connection.connectionString}) |
So if the db config is set as the example in the docs, the setup defaults to an empty string that throws an authentication error. And if driver is not set, it defaults to pglite.
But if DATABASE_URL is set everything works fine. As its said in the docs:
NuxtHub automatically detects your database connection using environment variables:
Uses PGlite (embedded PostgreSQL) if no environment variables are set.
Uses postgres-js driver if you set DATABASE_URL, POSTGRES_URL, or POSTGRESQL_URL environment variable.
Use neon-http driver with @neondatabase/serverless for [Neon](https://neon.com/) serverless PostgreSQL.
So setting connectionString with DATABASE_URL might give the illusion that connectionString is being read, but instead, is being read directly from the env variables.
I just filed this issue to document the behavior.