#Run migration on startup rather than first request
9 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
Community-Help:
Give https://payloadcms.com/docs/database/migrations#running-migrations-in-production a try
Passing your migrations as shown above will tell Payload, in production only, to execute any migrations that need to be run prior to completing the initialization of Payload. This is ideal for long-running services where Payload will only be initialized at startup.
I hope it helps!
Thanks, that exactly where I put the migrations script and it runs on first request not initial load sadly
Perhaps Payload doesn't get initialised until first request in general? Seems weird though as I see the log to say the server is running, then I send a request, then the migrations run
This is more NextJS behaviour than Payload. Stuff does not run until requested, so all of Payload is un-initialized until the first request for any route that uses it (page or api).
You can probably cause such a request to happen at server start by using the NextJS instrumentation feature: https://nextjs.org/docs/app/guides/instrumentation
Ok thanks, we do something like that for our Hono server and OTEL. I'll try again with the pipeline migration and see if we can get that working (since it is a better solution tbh) cheers
Couldn't you simply change the start script to pnpm payload migrate && pnpm start?