Skip to content

fix: set NETLIFY_DB_DRIVER when running netlify dev#8219

Merged
pieh merged 1 commit intomainfrom
fix/local-drizzle
Apr 28, 2026
Merged

fix: set NETLIFY_DB_DRIVER when running netlify dev#8219
pieh merged 1 commit intomainfrom
fix/local-drizzle

Conversation

@pieh
Copy link
Copy Markdown
Contributor

@pieh pieh commented Apr 28, 2026

🎉 Thanks for submitting a pull request! 🎉

Summary

We should not fall into neon case when running locally (ref https://github.com/drizzle-team/drizzle-orm/blob/v1.0.0-beta.22/drizzle-orm/src/netlify-db/driver.ts#L239-L245 for currently released drizzle-kit@neta)


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved database configuration handling to automatically set the database driver when a database URL is configured, ensuring proper driver selection during development.

Walkthrough

The change modifies the Netlify dev command initialization to set an additional environment variable when a database URL is configured. Specifically, when NETLIFY_DB_URL is present, the code now also sets NETLIFY_DB_DRIVER to the value 'server'. This addition configures the database driver selection in the process environment alongside the existing database URL configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: setting NETLIFY_DB_DRIVER when running netlify dev, which aligns with the code modification.
Description check ✅ Passed The description is related to the changeset, explaining the motivation for setting NETLIFY_DB_DRIVER to avoid falling into the neon case when running locally.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/local-drizzle

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 and usage tips.

@github-actions
Copy link
Copy Markdown

📊 Benchmark results

Comparing with d5f2ab1

  • Dependency count: 1,061 (no change)
  • Package size: 355 MB (no change)
  • Number of ts-expect-error directives: 356 (no change)

@pieh pieh marked this pull request as ready for review April 28, 2026 11:15
@pieh pieh requested a review from a team as a code owner April 28, 2026 11:15
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@src/commands/dev/programmatic-netlify-dev.ts`:
- Around line 57-60: The code sets process.env.NETLIFY_DB_DRIVER but doesn't set
the structured env object like env.NETLIFY_DB_URL; update the block that checks
process.env.NETLIFY_DB_URL to also assign env.NETLIFY_DB_DRIVER = { sources:
['internal'], value: 'server' } (instead of only setting
process.env.NETLIFY_DB_DRIVER) so NETLIFY_DB_DRIVER follows the same internal
env pattern as env.NETLIFY_DB_URL.
🪄 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

Run ID: 8e437df4-c160-4863-adf7-49e0d418f657

📥 Commits

Reviewing files that changed from the base of the PR and between d5f2ab1 and e69a12c.

📒 Files selected for processing (1)
  • src/commands/dev/programmatic-netlify-dev.ts

Comment on lines 57 to 60
if (process.env.NETLIFY_DB_URL) {
env.NETLIFY_DB_URL = { sources: ['internal'], value: process.env.NETLIFY_DB_URL }
process.env.NETLIFY_DB_DRIVER = 'server'
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check usage of the env parameter and NETLIFY_DB_DRIVER references

# Search for where StartNetlifyDevOptions.env or the env parameter is used
echo "=== Usage of env parameter from startNetlifyDev ==="
rg -n -C3 'startNetlifyDev' --type=ts

echo -e "\n=== References to NETLIFY_DB_DRIVER in the codebase ==="
rg -n -C3 'NETLIFY_DB_DRIVER' --type=ts

echo -e "\n=== Pattern of env object assignments (to understand structure) ==="
rg -n 'env\.\w+\s*=\s*\{.*sources.*value' --type=ts -A1 -B1

Repository: netlify/cli

Length of output: 2687


🏁 Script executed:

#!/bin/bash

# Check how the env object is passed to netlifyDev and what it expects
echo "=== netlifyDev function and its parameters ==="
rg -n "const netlifyDev\s*=" --type=ts -A5

echo -e "\n=== Where netlifyDev is called/invoked ==="
rg -n "netlifyDev(" --type=ts -B3 -A3

echo -e "\n=== Check programmatic-netlify-dev.ts context around netlifyDev ==="
sed -n '50,80p' src/commands/dev/programmatic-netlify-dev.ts

Repository: netlify/cli

Length of output: 1661


🏁 Script executed:

#!/bin/bash

# Check where startNetlifyDev is called and how the return value is used
echo "=== Callers of startNetlifyDev ==="
rg -n "startNetlifyDev" --type=ts -B2 -A5 | head -80

echo -e "\n=== Check dev.ts full context where startProgrammaticNetlifyDev is used ==="
sed -n '1,150p' src/commands/dev/dev.ts | tail -60

Repository: netlify/cli

Length of output: 3532


🏁 Script executed:

#!/bin/bash

# Find where startProgrammaticNetlifyDev is actually called
echo "=== Call to startProgrammaticNetlifyDev ==="
rg -n "startProgrammaticNetlifyDev\s*\(" --type=ts -B2 -A10

# Also check the complete file structure of dev.ts to see the flow
echo -e "\n=== Lines 130-200 of dev.ts (to see how startProgrammaticNetlifyDev is used) ==="
sed -n '130,200p' src/commands/dev/dev.ts

Repository: netlify/cli

Length of output: 3170


🏁 Script executed:

#!/bin/bash

# Check if injectEnvVariables is called multiple times
echo "=== All calls to injectEnvVariables ==="
rg -n "injectEnvVariables" --type=ts -B2 -A2

# Check the function definition and what it does
echo -e "\n=== injectEnvVariables function definition ==="
rg -n "export.*injectEnvVariables\|function injectEnvVariables" --type=ts -A10

Repository: netlify/cli

Length of output: 4736


🏁 Script executed:

#!/bin/bash

# Check where NETLIFY_DB_URL might be set before startProgrammaticNetlifyDev
echo "=== All references to NETLIFY_DB_URL in dev.ts ==="
sed -n '1,200p' src/commands/dev/dev.ts | rg -n "NETLIFY_DB" || echo "No matches in first 200 lines"

# Check how injectEnvVariables actually works
echo -e "\n=== injectEnvVariables implementation ==="
sed -n '220,240p' src/utils/dev.ts

Repository: netlify/cli

Length of output: 1088


🏁 Script executed:

#!/bin/bash

# Check if NETLIFY_DB_URL is set anywhere else before line 57 of programmatic-netlify-dev.ts
echo "=== All NETLIFY_DB_URL references across codebase ==="
rg -n "NETLIFY_DB_URL" --type=ts -B1 -A1

echo -e "\n=== Check if there's any env object manipulation before startProgrammaticNetlifyDev ==="
sed -n '140,190p' src/commands/dev/dev.ts | rg -n "NETLIFY_DB\|env\s*=" || echo "No matches"

Repository: netlify/cli

Length of output: 4963


Set env.NETLIFY_DB_DRIVER consistently with env.NETLIFY_DB_URL.

Line 58 sets env.NETLIFY_DB_URL using the structured format with { sources: ['internal'], value: ... }, which follows the codebase pattern for internal environment variables. However, line 59 only sets process.env.NETLIFY_DB_DRIVER without setting env.NETLIFY_DB_DRIVER. For consistency with the established pattern (seen in env.NETLIFY_DEV, env.BLOBS_CONTEXT, etc.), also set:

  if (process.env.NETLIFY_DB_URL) {
    env.NETLIFY_DB_URL = { sources: ['internal'], value: process.env.NETLIFY_DB_URL }
+   env.NETLIFY_DB_DRIVER = { sources: ['internal'], value: 'server' }
    process.env.NETLIFY_DB_DRIVER = 'server'
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.NETLIFY_DB_URL) {
env.NETLIFY_DB_URL = { sources: ['internal'], value: process.env.NETLIFY_DB_URL }
process.env.NETLIFY_DB_DRIVER = 'server'
}
if (process.env.NETLIFY_DB_URL) {
env.NETLIFY_DB_URL = { sources: ['internal'], value: process.env.NETLIFY_DB_URL }
env.NETLIFY_DB_DRIVER = { sources: ['internal'], value: 'server' }
process.env.NETLIFY_DB_DRIVER = 'server'
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/dev/programmatic-netlify-dev.ts` around lines 57 - 60, The code
sets process.env.NETLIFY_DB_DRIVER but doesn't set the structured env object
like env.NETLIFY_DB_URL; update the block that checks process.env.NETLIFY_DB_URL
to also assign env.NETLIFY_DB_DRIVER = { sources: ['internal'], value: 'server'
} (instead of only setting process.env.NETLIFY_DB_DRIVER) so NETLIFY_DB_DRIVER
follows the same internal env pattern as env.NETLIFY_DB_URL.

@pieh pieh merged commit 3ececcd into main Apr 28, 2026
52 of 54 checks passed
@pieh pieh deleted the fix/local-drizzle branch April 28, 2026 11:30
pieh pushed a commit that referenced this pull request Apr 28, 2026
🤖 I have created a release *beep* *boop*
---


## [26.0.0](v25.6.2...v26.0.0)
(2026-04-28)


### ⚠ BREAKING CHANGES

* add support for new Netlify Database primitive
([#8212](#8212))

### Features

* add support for new Netlify Database primitive
([#8212](#8212))
([a153489](a153489))


### Bug Fixes

* set NETLIFY_DB_DRIVER when running netlify dev
([#8219](#8219))
([3ececcd](3ececcd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
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.

2 participants