// @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);