Skip to content

fix(database): push-schema.js CLI-entrypoint guard checks argv[1], not import.meta.url - #358

Merged
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernit-com-au:fix-push-schema-cli-guard
Aug 30, 2026
Merged

fix(database): push-schema.js CLI-entrypoint guard checks argv[1], not import.meta.url#358
telivity-otaip merged 1 commit into
TelivityAI:mainfrom
modernit-com-au:fix-push-schema-cli-guard

Conversation

@modernitconsultants

Copy link
Copy Markdown
Collaborator

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.

…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.
@telivity-otaip
telivity-otaip merged commit 24ce09f into TelivityAI:main Aug 30, 2026
5 checks passed
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