Skip to content

Fixed knex-migrator config loading after TypeScript conversion#29324

Merged
cmraible merged 2 commits into
mainfrom
codex/fix-migrator-config-tsx-loader
Jul 14, 2026
Merged

Fixed knex-migrator config loading after TypeScript conversion#29324
cmraible merged 2 commits into
mainfrom
codex/fix-migrator-config-tsx-loader

Conversation

@cmraible

@cmraible cmraible commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

no refs

MigratorConfig.js loaded the shared configuration before registering tsx/cjs. After shared config moved to TypeScript, that bare CLI load failed with MODULE_NOT_FOUND, which knex-migrator misleadingly surfaced as a missing config file.

Register the existing guarded tsx/cjs hook before any TypeScript-backed server modules. The guard remains unchanged so production installs can continue without tsx, and a bare-Node subprocess test covers the CLI loading path.

Also: added root migrate:db and rollback:db scripts that run knex-migrator inside ghost-dev against the MySQL database used by pnpm dev (or the sqlite database used by pnpm dev:sqlite). Additional knex-migrator options are forwarded naturally, avoiding a manual container shell.

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.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

MigratorConfig.js now conditionally registers tsx/cjs before loading migration-related server dependencies. A unit test verifies the module can be required from a bare Node subprocess. package.json adds scripts to run database migrations and rollbacks inside the ghost-dev container.

Suggested labels: migration

Suggested reviewers: 9larsons

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: knex-migrator config loading after the TypeScript conversion.
Description check ✅ Passed The description matches the changes by explaining the tsx hook fix, the new tests, and the new migration scripts.
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.
✨ 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 codex/fix-migrator-config-tsx-loader

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.

@nx-cloud

nx-cloud Bot commented Jul 14, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 552dd34

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

@cmraible cmraible changed the title 🐛 Fixed knex-migrator config loading after TypeScript conversion Fixed knex-migrator config loading after TypeScript conversion Jul 14, 2026
@acburdine

Copy link
Copy Markdown
Member

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.
@cmraible cmraible changed the title Fixed knex-migrator config loading after TypeScript conversion 🐛 Fixed knex-migrator config loading after TypeScript conversion Jul 14, 2026
@cmraible cmraible changed the title 🐛 Fixed knex-migrator config loading after TypeScript conversion Fixed knex-migrator config loading after TypeScript conversion Jul 14, 2026
@cmraible cmraible marked this pull request as ready for review July 14, 2026 21:05

@coderabbitai coderabbitai Bot left a comment

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.

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 win

Only suppress MODULE_NOT_FOUND for tsx/cjs itself

If tsx/cjs loads 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0994574 and 552dd34.

📒 Files selected for processing (3)
  • ghost/core/MigratorConfig.js
  • ghost/core/test/unit/migrator-config.test.js
  • package.json

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.01%. Comparing base (50b6f7c) to head (552dd34).
⚠️ Report is 11 commits behind head on main.

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              
Flag Coverage Δ
admin-tests 55.32% <ø> (+<0.01%) ⬆️
e2e-tests 76.11% <ø> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cmraible

Copy link
Copy Markdown
Collaborator Author

No worries, thanks for taking a look!

@cmraible cmraible merged commit 0ec72f5 into main Jul 14, 2026
52 checks passed
@cmraible cmraible deleted the codex/fix-migrator-config-tsx-loader branch July 14, 2026 21:23
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