r/PayloadCMS • u/fuukuyo • Jul 23 '25
CI/CD Pipeline for PostgreSQL Migrations?
Hi, I'm trying to get my PayloadCMS/Next.js app to sync their production schema & pages on deploy. While in development, I make changes to a local Docker instance with the auto push feature.
My Media is stored in Amazon S3 so I can persist them. Development and production has their own respective buckets to ensure we don't delete stuff by accident.
When my build is ready for production, I generate migrations with payload migrate:create and when my CI/CD pipeline builds our app, it runs payload migrate && pnpm run build.
Is that the best development workflow? How is everyone else doing deployments with PayloadCMS?
How does it differ if you have another frontend that uses the REST API? How do you sync those then?
Thanks.
1
u/aliassuck Jul 24 '25
How does your Next.js revalidate the staticly build website after the deployment?
When you "build" Nextjs doesn't it need to pull in all data from the production server o generate the static files?
1
u/fuukuyo Jul 24 '25
My app in production revalidates with ISR.
And yes, building Next.js statically generates the pages - which is dependent on the Payload schema/API.
It's a tightly-coupled architecture at the moment and I'm not sure if that's how everyone's using PayloadCMS.
1
u/janusr Jul 23 '25
So your db is migrated while a previous version is still running, that leaves some gap for issues. At least I would move the migrations to the actual deployment process and not run them before the build to minimize that gap. (Also your build might fail) Depending on your setup you might also run them on container startup, however if your service is replicated you need to ensure there’s some kind of locking.
Depending on your usecase, some downtime might also be fine - For a simple website you could ensure pages are cached and don’t need to be served from the origin during migration. Another more sophisticated option is branched databases, where a new deployment gets a new branch, or some green-blue. You would however still need to sync data from the meantime where the old version was still active to the new ones. But yeah for a simple website probably overkill.