payload icon indicating copy to clipboard operation
payload copied to clipboard

`payload migrate` hangs in CI/Docker after dev-mode push; `--force-accept-warning` is ignored on 3.x

Open anthonysantiago-eng opened this issue 1 month ago • 2 comments

Describe the Bug

If a Postgres/SQLite database has ever been touched by Payload in dev mode (push enabled, the default), pushDevSchema writes a { name: 'dev', batch: -1 } row to payload_migrations. After that, payload migrate always shows the "It looks like you've run Payload in dev mode..." confirm prompt.

In a non-interactive deploy (CI runner, docker run without -it) nobody can answer it, so the deploy hangs until it times out. The documented --force-accept-warning flag doesn't help: bin/migrate.ts parses it and passes it to migrate:create and migrate:fresh, but case 'migrate' calls adapter.migrate() with no arguments, and drizzle's migrate() has no option to skip the prompt. Answering "no" calls process.exit(0), so a cancelled migration also looks like a successful deploy.

The only workaround today is deleting the dev row by hand (as suggested in #7986). I hit this on a production Next.js + Payload 3 app deployed via GitHub Actions, and #7986 / discussion #14973 describe the same thing (#14973: seeding or running int tests against a database is enough to create the row).

This is already fixed on main: cli/commands/migrate/run.ts passes forceAcceptWarning through and drizzle migrate() honors it. 3.x doesn't have the fix.

Link to the code that reproduces this issue

https://github.com/anthonysantiago-eng/payload-3x-migrate-dev-prompt-repro

Reproduction Steps

  1. docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:17 and npm install
  2. npm run migrate: applies the one committed migration (batch 1)
  3. npm run dev-boot: calls getPayload() once in dev mode; payload_migrations now also contains dev | -1
  4. Run migrations the way a deploy would:
Command Result (Linux node:22, and Windows 11)
npm run migrate </dev/null Prompt is printed, process hangs (killed by timeout, exit 124)
sleep 60 | npm run migrate (stdin open, no input) Hangs
npm run migrate -- --force-accept-warning </dev/null Hangs, flag is ignored
echo n | npm run migrate No migrations run, exit code 0

Which area(s) are affected?

db: postgres, db: sqlite (shared @payloadcms/drizzle code). MongoDB has no equivalent prompt.

Environment Info

payload: 3.92.0
@payloadcms/db-postgres: 3.92.0
Node.js: 22.23.4 (also 24.22.1)
PostgreSQL: 17
OS: Linux (node:22-bookworm container), Windows 11

Proposed fix (happy to open the PR)

Backport the main behavior to 3.x, without changing the default:

  1. packages/payload/src/database/types.ts: add forceAcceptWarning?: boolean to the migrate args
  2. packages/drizzle/src/migrate.ts: skip the prompt when forceAcceptWarning is true
  3. packages/payload/src/bin/migrate.ts: pass forceAcceptWarning in case 'migrate'
  4. Drizzle-only int test (seed a batch: -1 row, assert migrate runs with the flag) + document the warning and flag under ### Migrate in docs/database/migrations.mdx

Questions before I start:

  • Are fixes like this still accepted on 3.x now that v4 is in beta?
  • Would you also want non-interactive runs (no TTY, no flag) to fail with a non-zero exit and a message naming the dev row and the flag, instead of hanging? I'd keep that out of the first PR unless you want it.

Related observation on main (4.0.0-beta.4)

Same repro, no TTY: without --json, payload migrate prints the prompt, then Node exits with code 13 ("Detected unsettled top-level await"). With --json it returns {"cancelled":true} with "success":true and exits 0. Not part of this issue, but mentioning it in case the non-interactive behavior is worth aligning.

anthonysantiago-eng avatar Oct 26 '26 05:10 anthonysantiago-eng

Hi, I’d like to work on this issue. I can reproduce the non-interactive payload migrate hang and will look into backporting the --force-accept-warning behavior to 3.x, with a focused test and documentation update. Before I start could you confirm that a 3.x fix is still welcome?

irinesara avatar Oct 28 '26 05:10 irinesara

Hi @irinesara, thanks for the interest! I've already opened a PR for this: #19080. It backports --force-accept-warning to plain migrate on 3.x, with an int test and a docs update. It's waiting on maintainer review now. If you'd like to help, testing it or reviewing it would be very welcome.

anthonysantiago-eng avatar Oct 28 '26 05:10 anthonysantiago-eng