fix(db): lazy URL resolution for Docker/K8s deployments#790
Merged
atinux merged 1 commit intonuxt-hub:mainfrom Jan 21, 2026
Merged
fix(db): lazy URL resolution for Docker/K8s deployments#790atinux merged 1 commit intonuxt-hub:mainfrom
atinux merged 1 commit intonuxt-hub:mainfrom
Conversation
|
@onmax is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
98ad0d4 to
48a39f6
Compare
|
Can the I just ran into this issue while trying to build a generic container image for Kubernetes deployments and it defaults to a local database (which instantly crashes on runtime since the container filesystem is read only) |
180b34a to
dff01b5
Compare
dff01b5 to
4bcd403
Compare
atinux
approved these changes
Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #777
Summary
Allow building without DATABASE_URL when
applyMigrationsDuringBuild: false. Generate lazy Proxy pattern for postgres-js, neon-http, mysql2, libsql on non-CF deployments. Enables Docker multi-client scenario: build once, deploy many with different DATABASE_URLs.StackBlitz
CLI Reproduction
Verify fix
The
-fixedfolder uses pnpm patch to apply the fix locally.Related
Context
Details
Kenshi:
Hey,
I recently switched to Nuxt-Hub for the simple database implementation and S3 support, but I have run into an issue I can't figure out how to work around. I'm working with Docker to deploy my Nuxt app and build my own Docker images for each one. After building a Nuxt app that's using the Nuxt Hub without setting anything besides the db: 'postgresql', it causes an error to occur on launch Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@electric-sql/pglite' imported from /prod/server/node_modules/drizzle-orm/pglite/driver.js. I tried to follow the documentation and had set the driver to postgres-js but that causes another issue when building the app postinstall: ERROR postgres-js driver requires DATABASE_URL, POSTGRES_URL, or POSTGRESQL_URL environment variable. It is not suitable for me to set the ENV variables on build as the app is being deployed for multiple clients and these change on every Nuxt Instance.
Could you suggest any workaround for this issue? If there are any.
Thanks in advance.
EDIT: I have also tried setting the applyMigrationsDuringBuild to false but nothing changed
NuxtHub needs to know the database env in order to apply the database migrations at build time
Kenshi
—
Yesterday at 8:54 AM
Yeah, I'm aware of that, that's why I tried to disable the migration at build as stated in the docs.
Atinux
—
Yesterday at 8:57 AM
Could you try to set a fake DATABASE_URL for the build to see if it passes?
If you disabled migrations it shouldn’t call the database anyway
Kenshi
—
Yesterday at 8:59 AM
We did try that, but apparently nuxt hub hard codes the variable into the cooked build instead of reading it from the env file
Feels counter intuitive to me but it is what it is
It's for all of the variables as well not only the database
Atinux
—
Yesterday at 10:52 AM
It should be possible to fix this
How do you plan to manage the migrations @kenshi ?
Atinux
—
Yesterday at 11:22 AM
what do you think of this @onmax ?
onmax
—
Yesterday at 1:09 PM
Connection URL gets hardcoded into generated hub/db.mjs at build time via JSON.stringify(connection). Cloudflare deployments (D1, Hyperdrive) work because they use lazy runtime resolution:
const binding = process.env.DB || globalThis.env?.DB
Non-CF deployments (postgres-js, neon-http, mysql2) don't have this.
I propose always use lazy resolution for non-CF drivers too. Zero config changes, Docker multi-client deployments would work:
function getDB() {
const url = process.env.DATABASE_URL || process.env.POSTGRES_URL
if (!url) throw new Error('DATABASE_URL required')
return drizzle({ connection: url, schema })
}
Also: only require DATABASE_URL at build time if applyMigrationsDuringBuild: true.
Should I open a PR @atinux ? Would close #777 as well.
Did i miss something?
Kenshi
—
Yesterday at 1:32 PM
We have it run checks and in case of changes migrations at the app launch. It might not be the cleanest solution but it works for our use case as of right now.
Vetro
—
Yesterday at 2:07 PM
Hey, I work with @kenshi . It would be great if migrations could be done on application deploy, not just on build.
Also I found, that probably whole hub's config is baked into nuxt's nitro.mjs on build... blob config what was in env file (api keys for S3) is also here
Atinux
—
Yesterday at 2:42 PM
sounds good!