fix(database): push-schema.js CLI-entrypoint guard checks argv[1], not import.meta.url - #358
Merged
telivity-otaip merged 1 commit intoAug 30, 2026
Conversation
…t import.meta.url The direct-invocation guard (node packages/database/dist/push-schema.js) compared import.meta.url against process.argv[1] to decide whether to run main(). tsup's ESM output code-splits this file's top-level statements into a shared chunk (dist/chunk-*.js), so import.meta.url inside that code resolves to the CHUNK's own URL, not push-schema.js's -- confirmed with debug logging, which showed the mismatch on every invocation, direct or imported. The practical effect: running push-schema.js standalone (as opposed to via run-migrations.js, which imports and calls pushSchema() directly, bypassing this guard entirely) silently did nothing -- no thrown error, no output, exit code 0 -- because main() was never called. permission-smoke.integration.spec.ts's beforeAll hits exactly this path, running push-schema.js standalone a second time to prove role_permissions grants survive a re-run against already-seeded data, and got zero grants back as a result. Checking process.argv[1]'s own filename instead of import.meta.url sidesteps bundler chunking entirely -- it only asks what script node was told to run, never where the executing code happens to live.
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.
The direct-invocation guard (
node packages/database/dist/push-schema.js) comparedimport.meta.urlagainstprocess.argv[1]to decide whether to runmain().tsup's ESM output code-splits this file's top-level statements into a shared chunk (
dist/chunk-*.js), soimport.meta.urlinside that code resolves to the chunk's own URL, notpush-schema.js's -- confirmed with debug logging, which showed the mismatch on every invocation, direct or imported.The practical effect: running push-schema.js standalone (as opposed to via run-migrations.js, which imports and calls
pushSchema()directly, bypassing this guard entirely) silently did nothing -- no thrown error, no output, exit code 0 -- becausemain()was never called.permission-smoke.integration.spec.ts's beforeAll hits exactly this path, running push-schema.js standalone a second time to proverole_permissionsgrants survive a re-run against already-seeded data, and got zero grants back as a result.Checking
process.argv[1]'s own filename instead ofimport.meta.urlsidesteps bundler chunking entirely -- it only asks what script node was told to run, never where the executing code happens to live.