payload's pushDevSchema() awaits prompts() whenever drizzle push reports warnings (incl. DATA LOSS); under non-TTY stdin that await hangs forever (2026-10-19 bootstrap hang). Inject confirmations through the single hoisted prompts copy before getPayload boots; stdio stays inherit so all other push output remains visible.
31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
// @ts-expect-error - the `prompts` package ships no bundled types; only `.inject()` is used here.
|
|
import prompts from "prompts";
|
|
import { getPayload } from "payload";
|
|
import config from "@payload-config";
|
|
|
|
/**
|
|
* One-shot schema push for the test database. Run with DB_PUSH=1 and
|
|
* DATABASE_URI pointing at the test database (tests/test-db.ts does this);
|
|
* initializing the Payload adapter with push: true makes drizzle create or
|
|
* diff the full schema. Exits immediately after initialization.
|
|
*
|
|
* Non-interactive by construction: when drizzle push reports warnings
|
|
* (including DATA LOSS ones), @payloadcms/drizzle's pushDevSchema asks via
|
|
* `prompts()`. Under a non-TTY stdin that await hangs forever, so we pre-load
|
|
* the SAME hoisted `prompts` module Payload imports and inject confirmations
|
|
* for it. The injected queue never empties in practice (one confirm per run,
|
|
* ten prepared); if it ever did, prompts would fall back to stdin, which is
|
|
* exactly why the queue is generous rather than exactly one.
|
|
*
|
|
* This relies on module identity: bun's loader resolves every `import
|
|
* prompts from "prompts"` to the single hoisted copy in node_modules (verified
|
|
* no nested copies under payload's own node_modules subtree). If a future
|
|
* dependency bump nests a second copy, the injection silently stops applying
|
|
* and pushes with warnings hang again - watch for that when touching deps.
|
|
*/
|
|
prompts.inject(Array(10).fill(true));
|
|
console.log("[push-schema] non-interactive mode: any drizzle push warnings/data-loss confirmations are auto-accepted");
|
|
|
|
const payload = await getPayload({ config });
|
|
void payload;
|
|
process.exit(0);
|