fix(postgres): fail fast when SQL loader directory cannot be resolved - #4482
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix code according to review comments
fix(postgres): fail fast when SQL loader directory cannot be resolved
Aug 3, 2026
manast
marked this pull request as ready for review
August 3, 2026 21:16
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the PostgreSQL SQL asset loader so it never silently falls back to process.cwd() when its module directory can’t be resolved, and instead fails fast with an explicit error. This reduces the risk of confusing ENOENTs or accidentally loading unintended SQL files from the working directory.
Changes:
- Added a
getDirname()resolver to derive the loader’s directory in a CJS/ESM-compatible way and throw when it can’t be determined. - Bound
MIGRATIONS_DIR/COMMANDS_DIRto the resolved module directory (currentDir) instead of relying on implicit cwd behavior. - Added a focused Postgres test file covering migration SQL loading, command SQL loading, and intended cache behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/postgres/sql-loader.ts |
Computes a stable module directory and derives migrations/commands paths from it, throwing if resolution fails. |
tests/postgres/sql_loader.test.ts |
Adds basic runtime coverage for migration/command SQL loading and attempts to validate caching behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
manast
force-pushed
the
copilot/fix-review-comments-4473
branch
from
August 4, 2026 10:22
3d1cf49 to
7b1bb71
Compare
roggervalf
force-pushed
the
copilot/fix-review-comments-4473
branch
3 times, most recently
from
August 5, 2026 01:51
222d020 to
ff7dbed
Compare
roggervalf
approved these changes
Aug 5, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
roggervalf
force-pushed
the
copilot/fix-review-comments-4473
branch
from
August 5, 2026 03:14
ff7dbed to
0c0da2c
Compare
Contributor
|
🎉 This PR is included in version 6.0.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
|
🎉 This PR is included in version 3.0.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Port Impact Checklist
Why
A PR review identified that
sql-loadercould fall back to''when directory resolution failed, causing SQL asset lookup to become relative toprocess.cwd(). This risks confusing ENOENTs or loading unintended SQL files from the working directory.How
Directory resolution hardening
getDirname()resolution path for CJS/ESM compatibility (__dirnamefirst, then stack/file URL resolution).SQL path binding
MIGRATIONS_DIRandCOMMANDS_DIRnow always derive from the resolved module directory (currentDir), never from implicit cwd behavior.Focused loader coverage
tests/postgres/sql_loader.test.tscovering migration SQL loading, command SQL loading, and command SQL cache reuse.Additional Notes (Optional)
This change is scoped to the review-thread concern only: fail fast on unresolved loader directory to prevent incorrect runtime SQL path resolution.