Skip to content

fix(nuxthub): handle object form of hub.db - #3822

Open
benjamincanac wants to merge 5 commits into
mainfrom
fix/nuxthub-db-object-form
Open

fix(nuxthub): handle object form of hub.db#3822
benjamincanac wants to merge 5 commits into
mainfrom
fix/nuxthub-db-object-form

Conversation

@benjamincanac

Copy link
Copy Markdown
Member

🔗 Linked issue

Resolves #3821

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

The nuxthub preset only mapped the NuxtHub database config into content.database when hub.db was a string. With @nuxthub/core >= 0.10 the config can also be an object, in that case the check failed and content.database silently fell back to the default sqlite config, which picks better-sqlite3 at runtime and breaks every query endpoint on Vercel with ERR_DLOPEN_FAILED.

Both setup() and setupNitro() now gate on hub.db being truthy and read the resolved config from runtimeConfig.hub.db, which is always an object with driver and connection once NuxtHub has run (both hooks fire after modules:done).

The duplicated driver mapping is extracted into hubDatabaseToContentDatabase and now covers the driver names NuxtHub 0.10 actually resolves to: postgres-js and neon-http map to postgresql (the old fallthrough produced an invalid type: 'postgres-js'), better-sqlite3 maps to sqlite, and unsupported drivers (mysql2, d1-http) warn and fall back to the default database instead of producing an invalid config.

Added unit tests for the mapping, both hub.db forms, and the /tmp libsql rewrite in setupNitro.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
content Ready Ready Preview Jul 30, 2026 3:13pm

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3822

commit: 2744e23

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The NuxtHub preset adds database mapping that validates PostgreSQL URLs and SQLite filenames before producing Nuxt Content configuration. Both setup and setupNitro use the mapping for object-form hub.db values, while Nitro tests cover object- and string-form database handling, LibSQL path rewriting, and integrity checks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes align with #3821 by supporting object-form hub.db and preserving the libsql/tmp rewrite path.
Out of Scope Changes check ✅ Passed The patch stays focused on NuxtHub database mapping and related tests without obvious unrelated additions.
Title check ✅ Passed The title clearly and concisely matches the main change: handling object-form hub.db in the NuxtHub preset.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the bug fix and test coverage.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nuxthub-db-object-form

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 25-26: Update the database config mapper around the driver
allowlist to normalize aliases before returning ContentDatabaseConfig: map
postgres to postgresql, and map sqlite by converting connection.url to filename
instead of emitting url. Add or update mapper coverage for both sqlite and
postgres aliases while preserving existing handling for the other drivers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 20d8f438-ef48-4cbd-af04-0793edbf2f4a

📥 Commits

Reviewing files that changed from the base of the PR and between dc90e96 and c80e16c.

📒 Files selected for processing (2)
  • src/presets/nuxthub.ts
  • test/unit/nuxthubPreset.test.ts

Comment thread src/presets/nuxthub.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 19-23: Update the PostgreSQL and SQLite mapping branches in the
hub database preset to validate required connection values before returning a
config: require a non-empty URL for PostgreSQL and a non-empty filename or
URL-derived path for SQLite. Return undefined when validation fails so malformed
object-form hub.db values reach the existing warning/default fallback instead of
being accepted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f978a619-27fb-495f-92e2-37e28999c299

📥 Commits

Reviewing files that changed from the base of the PR and between c80e16c and 425b590.

📒 Files selected for processing (2)
  • src/presets/nuxthub.ts
  • test/unit/nuxthubPreset.test.ts

Comment thread src/presets/nuxthub.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 19-24: Update the PostgreSQL and SQLite branches around
hubDb.connection to validate runtime types before constructing the config:
accept url only when typeof value is "string", and for SQLite only use filename
when it is a string, otherwise use url.replace only when url is a string. Return
undefined when neither valid string value is available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8558e52c-5413-4940-8f0d-90830695976a

📥 Commits

Reviewing files that changed from the base of the PR and between 425b590 and 985308f.

📒 Files selected for processing (2)
  • src/presets/nuxthub.ts
  • test/unit/nuxthubPreset.test.ts

Comment thread src/presets/nuxthub.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/unit/nuxthubPreset.test.ts (1)

111-115: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the unsupported-driver warning.

This test verifies only that options.database remains unset. Also spy on the warning path and assert it is called, so silent fallback regressions cannot pass. Per the PR objective, unsupported drivers must warn before falling back.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/nuxthubPreset.test.ts` around lines 111 - 115, Update the
unsupported-driver test around nuxthubPreset.setup to spy on the warning/logging
path used for unsupported database drivers, then assert it is called during
setup before retaining the existing options.database undefined assertion. Use
the existing warning symbol and verify the fallback emits a warning for the
MySQL configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/unit/nuxthubPreset.test.ts`:
- Around line 111-115: Update the unsupported-driver test around
nuxthubPreset.setup to spy on the warning/logging path used for unsupported
database drivers, then assert it is called during setup before retaining the
existing options.database undefined assertion. Use the existing warning symbol
and verify the fallback emits a warning for the MySQL configuration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bfed1549-ec5d-4de8-ac7b-4b3d2893b5a3

📥 Commits

Reviewing files that changed from the base of the PR and between 985308f and 8d1f631.

📒 Files selected for processing (2)
  • src/presets/nuxthub.ts
  • test/unit/nuxthubPreset.test.ts

@benjamincanac benjamincanac changed the title fix(nuxthub): handle object form of hub.db fix(nuxthub): handle object form of hub.db Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nuxthub preset ignores the object form of hub.db and falls back to better-sqlite3

1 participant