#46
Fix Railway migration runtime
Summary
- bundle the Postgres migration script into the slim TanStack Start runner image
- keep the existing Railway pre-deploy command and service configuration unchanged
- add esbuild as an explicit build dependency
Root cause
The runner copied scripts/migrate.mjs without node_modules, so staging pre-deploy failed with ERR_MODULE_NOT_FOUND for pg. Demo succeeded because it does not run database migrations.
Validation
- pnpm install --frozen-lockfile
- pnpm lint
- pnpm typecheck
- pnpm test (169 passed)
- pnpm build
- Docker image build
- bundled migration applied all 11 migrations to temporary Postgres and was idempotent
- final container /api/health returned 200
Activity
6mikeyreviewed2mo ago
12f89e2 into main2mo ago
Review: Fix Railway migration runtime
Verification performed (not just static reading): reproduced the actual failure/fix locally.
pg@8.23.0andesbuild@0.28.2(exact versions pinned in the lockfile) and ran the sameesbuildbundle command fromDockerfile:13againstscripts/migrate.mjs.node_modules(norequire('pg')left unresolved — this is exactly theERR_MODULE_NOT_FOUNDthe PR describes).pgnative-bindingrequire('pg-native')path (pg/lib/native/client.js) is wrapped in try/catch both pre- and post-bundle, so the bundle doesn't hard-fail whenpg-nativeisn't installed (it isn't, by design —pg-nativeis an optional peer dep here).migrate.mjsagainst it using this repo's actual 11 migration files (lib/db/migrations/0000_modern_vance_astro.sql…0010_purge-ai-provider-keys.sql). All 11 applied successfully in order, matching the PR's own validation notes.fileURLToPath(new URL("../lib/db/migrations/", import.meta.url))) still resolves correctly post-bundle, since the Dockerfile placesmigrate.mjsatrunner:/app/scripts/migrate.mjswithlib/db/migrationscopied torunner:/app/lib/db/migrations— same relative layout as the source tree, so no path breakage from the bundle/copy relocation (build:/app/migrate.mjs→runner:/app/scripts/migrate.mjs).Scope check: diff is minimal and matches the stated intent — one new
RUN esbuild ...layer in thebuildstage, theCOPYsource flipped to the bundled output, andesbuildadded as an explicit (already-transitive) devDependency with a matching lockfile entry. No unrelated changes.Result: No blocking correctness, security, or maintainability issues found. The fix addresses the described root cause and is empirically confirmed to produce a working, idempotent migration runner independent of
node_modules.Non-blocking observation: the
esbuildbundle command is duplicated as an inlineRUNstring in the Dockerfile with no pinned checksum verification beyond the lockfile — acceptable as-is, but if this pattern is reused for other scripts, moving it into a smallpackage.jsonscript (e.g.build:migrate) would keep the Dockerfile thinner and give the command a single source of truth. Not a blocker for this PR.