Fixed knex-migrator config loading after TypeScript conversion#29324
Conversation
no ref The shared config is now TypeScript-backed, so knex-migrator must register the guarded tsx hook before loading server modules. Keeping the existing fallback preserves production installs where tsx is unavailable.
Walkthrough
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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 |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many --target=build --projects=tag:publi... |
✅ Succeeded | <1s | View ↗ |
nx run @tryghost/admin-x-settings:test:acceptance |
✅ Succeeded | 9m 59s | View ↗ |
nx run-many -t test:unit -p ghost,@tryghost/ada... |
✅ Succeeded | 9m 18s | View ↗ |
nx run ghost:test:ci:integration |
✅ Succeeded | 2m 45s | View ↗ |
nx run ghost:test:integration |
✅ Succeeded | 2m 36s | View ↗ |
nx run ghost-monorepo:lint:boundaries |
✅ Succeeded | 7s | View ↗ |
nx run-many -t lint -p ghost,ghost-monorepo,@tr... |
✅ Succeeded | 3m 57s | View ↗ |
nx run @tryghost/admin:build |
✅ Succeeded | 3m 2s | View ↗ |
Additional runs (11) |
✅ Succeeded | ... | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-07-14 21:15:13 UTC
|
whoops 🤦🏻♂️ sorry about that |
no ref Developers need a direct way to run knex-migrator against the MySQL database in ghost-dev while forwarding CLI options without opening a container shell.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ghost/core/MigratorConfig.js (1)
5-18: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winOnly suppress
MODULE_NOT_FOUNDfortsx/cjsitselfIf
tsx/cjsloads but one of its dependencies is broken, this catch turns it into a silent “tsx unavailable” path and hides the real failure. Narrow the guard to the requested module name.Proposed fix
catch (error) { - if (error.code !== 'MODULE_NOT_FOUND') { + if (error.code !== 'MODULE_NOT_FOUND' || !error.message.includes("'tsx/cjs'")) { throw error; } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ghost/core/MigratorConfig.js` around lines 5 - 18, Update the catch guard around the top-level require('tsx/cjs') so MODULE_NOT_FOUND is suppressed only when the missing module is exactly 'tsx/cjs'. Inspect the caught error’s module identifier, such as its message or require-stack metadata, and rethrow errors caused by missing dependencies or any other failure; preserve the existing successful registration path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@ghost/core/MigratorConfig.js`:
- Around line 5-18: Update the catch guard around the top-level
require('tsx/cjs') so MODULE_NOT_FOUND is suppressed only when the missing
module is exactly 'tsx/cjs'. Inspect the caught error’s module identifier, such
as its message or require-stack metadata, and rethrow errors caused by missing
dependencies or any other failure; preserve the existing successful registration
path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c0475a81-5e5d-41a0-b7ed-f86c0e56f4de
📒 Files selected for processing (3)
ghost/core/MigratorConfig.jsghost/core/test/unit/migrator-config.test.jspackage.json
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #29324 +/- ##
==========================================
+ Coverage 73.93% 74.01% +0.08%
==========================================
Files 1579 1577 -2
Lines 136891 136812 -79
Branches 16552 16570 +18
==========================================
+ Hits 101204 101259 +55
+ Misses 34678 34544 -134
Partials 1009 1009
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No worries, thanks for taking a look! |

no refs
MigratorConfig.jsloaded the shared configuration before registeringtsx/cjs. After shared config moved to TypeScript, that bare CLI load failed withMODULE_NOT_FOUND, which knex-migrator misleadingly surfaced as a missing config file.Register the existing guarded
tsx/cjshook before any TypeScript-backed server modules. The guard remains unchanged so production installs can continue withouttsx, and a bare-Node subprocess test covers the CLI loading path.Also: added root
migrate:dbandrollback:dbscripts that run knex-migrator insideghost-devagainst the MySQL database used bypnpm dev(or the sqlite database used bypnpm dev:sqlite). Additional knex-migrator options are forwarded naturally, avoiding a manual container shell.