fix(db): migrate script loads repo-root .env - #16
Merged
Conversation
`pnpm migrate:dev` from a clean shell failed with "DATABASE_URL_ADMIN is not set" because the runner only read process.env and nothing loaded .env. Load the repo-root .env via process.loadEnvFile() before reading the vars - anchored to the script's own path, since `pnpm --filter` runs with packages/db as the cwd. A missing .env is swallowed, so CI and production (which set the vars directly) are unaffected. Verified from a clean shell with nothing exported: - .env present, DB already migrated -> exit 0, no error - DATABASE_URL_ADMIN sourced only from .env -> applies all 13 - no .env + var exported -> works - no .env + nothing set -> the intended "not set" error, no crash Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Puf9jhj137U3iswf4GWZkG Signed-off-by: Matthew Wren <info@origindev.com>
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.
Problem
pnpm migrate:devfrom a clean shell fails withDATABASE_URL_ADMIN is not seteven though.envdefines it. The runner only readsprocess.env, and nothing loads.env.Fix
packages/db/src/migrate.tscallsprocess.loadEnvFile()on the repo-root.envbefore reading the connection vars. The path is resolved from the script's own location (import.meta.dirname→../../../.env), not the cwd, becausepnpm --filterruns withpackages/dbas the working directory. A missing file is caught and ignored, so CI and production — which set the vars directly — are unaffected. No new dependency (Node built-in).Verified from a clean shell, nothing exported
.envpresent, DB already migratedDATABASE_URL_ADMINsourced only from.env, fresh DB.env, var exported (CI/prod path)loadEnvFilethrow is swallowed.env, nothing setError: DATABASE_URL_ADMIN (or DATABASE_URL) is not set, not a stack trace fromloadEnvFilepnpm typecheck/lint/testpass.🤖 Generated with Claude Code