#Run migration on startup rather than first request

9 messages · Page 1 of 1 (latest)

short moon
#

I'm trying to set up Postgres migrations executing at runtime. It seems like Payload runs the migrations on first request rather than container boot up, this means we can't do proper blue/green deploys if the migration process fails. Is it possible to modify this behaviour?

kind ruinBOT
spiral fox
short moon
#

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

north sentinel
#

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).

short moon
#

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

stable urchin
#

Couldn't you simply change the start script to pnpm payload migrate && pnpm start?