Skip to content

feat(db0): allow disabling automatic table setup - #838

Open
elpisqe wants to merge 1 commit into
unjs:mainfrom
elpisqe:feat/db0-auto-setup
Open

elpisqe wants to merge 1 commit into
unjs:mainfrom
elpisqe:feat/db0-auto-setup

Conversation

@elpisqe

@elpisqe elpisqe commented Oct 4, 2026 •

Copy link
Copy Markdown

Resolves #833.

Adds an optional autoSetup flag to the db0 driver. Setting it to
false skips automatic table creation and propagates database errors
unchanged, allowing applications to provision the table separately.

The default remains true to preserve existing behavior.

Validation:

  • pnpm build and pnpm test: 557 passed, 226 skipped.
  • PostgreSQL 17.11 with an application role lacking schema CREATE
    privileges: reproduced the original failure and verified storage
    operations and unchanged missing-table errors with autoSetup: false.

Minimal reproduction

The regression test does not create the table when autoSetup is disabled
in test/drivers/db0.test.ts uses a pre-existing table and a fresh driver
configured with autoSetup: false.

Run it with:

pnpm exec vitest run test/drivers/db0.test.ts -t "does not create the table when autoSetup is disabled"

Without the fix, the test fails because the driver still executes
CREATE TABLE. With the fix, the read succeeds without attempting
table creation.

Summary by CodeRabbit

  • New Features
    • SQL database storage can now be configured to skip automatic table creation. This is useful when a compatible table is already provisioned; automatic setup remains enabled by default.
    • When automatic setup is disabled and the table is missing, the original database error is returned.
  • Documentation
    • Added setup guidance and an example for using the SQL driver with automatic table creation disabled.

@elpisqe
elpisqe requested a review from pi0 as a code owner October 4, 2026 12:29
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@elpisqe is attempting to deploy a commit to the unjs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ed616028-eee3-44b0-8d0d-02375a3c39cc
📥 Commits

Reviewing files that changed from the base of the PR and between 0dfd172 and efdb9fa.

📒 Files selected for processing (3)
  • docs/2.drivers/database.md
  • src/drivers/db0.ts
  • test/drivers/db0.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The db0 driver adds an autoSetup option. It defaults to true; when set to false, the driver skips automatic table creation. Tests and documentation cover both setup modes and missing-table errors.

Changes

db0 table setup

Layer / File(s) Summary
Configure automatic table setup
src/drivers/db0.ts, test/drivers/db0.test.ts, docs/2.drivers/database.md
The driver adds the optional autoSetup setting and skips table creation when it is false. Tests cover reads with setup disabled, default setup behavior, and propagation of missing-table errors. The documentation describes the required table schema and shows how to disable automatic setup.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to efdb9

No actionable issue remains; the change is ready for normal merge checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to efdb9

The change is opt-in and does not add database privileges or alter storage access controls. Applications disabling setup must provision a compatible table first. Production permission settings and handling of database errors remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The affected storage scope remains the configured database connection and table. Existing clear behavior deletes all rows in that table; the new option does not expand that SQL target or supply a new database identity.

Trust Boundaries and Controls

  • observed — autoSetup is supplied through driver configuration, not through storage keys or values. The guard controls provisioning only; operations continue through the supplied database connection, with no new identity or tenant transition in this driver path.
  • observed — Disabled setup exposes the underlying missing-table error to the storage caller, including the table name. The test establishes error identity preservation, but does not establish disclosure to an external requester or a bypass of application error-redaction controls.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding an option to disable automatic table setup in the db0 driver.
Linked Issues check ✅ Passed Issue #833 requests a way to disable automatic table creation and let missing-table database errors reach the application. DB0DriverOptions.autoSetup implements this switch. ensureTable skips setu…
Out of Scope Changes check ✅ Passed The source change, regression tests, and database driver documentation all support issue #833. The tests cover disabled setup, the existing default behavior, and missing-table error propagation. No un…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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.

Critical - db0 driver unusable when missing CREATE privilege on schema: option required to disable table autosetup

1 participant