fix: set NETLIFY_DB_DRIVER when running netlify dev#8219
Conversation
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThe change modifies the Netlify dev command initialization to set an additional environment variable when a database URL is configured. Specifically, when Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
📊 Benchmark resultsComparing with d5f2ab1
|
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/commands/dev/programmatic-netlify-dev.ts
| if (process.env.NETLIFY_DB_URL) { | ||
| env.NETLIFY_DB_URL = { sources: ['internal'], value: process.env.NETLIFY_DB_URL } | ||
| process.env.NETLIFY_DB_DRIVER = 'server' | ||
| } |
There was a problem hiding this comment.
🧩 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 -B1Repository: 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.tsRepository: 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 -60Repository: 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.tsRepository: 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 -A10Repository: 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.tsRepository: 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.
| 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.
🤖 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>
🎉 Thanks for submitting a pull request! 🎉
Summary
We should not fall into
neoncase 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:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)