How do you handle changing the configuration and database schema on a live environment ?
Here's the approach I tried, which didn't work:
1. Add a field in a collection in payload.config.ts
2. ( I say yes to the prompt, which reviews correctly the local database)
3. Commit / Push to backend repo / Pull live
4. Run
npm run build
on server
5. Run
npm run serve
on server
What am I missing? Should I look into migrations for this? As long as I stay in my local env it's fine, because I use
npm run dev
and have that prompt to which I say yes. But when going live and not using
npm run dev
, how do I do it ?
Thanks
You will need to explicitly run your migrations against the database. ie.
payload migrate
before running serve. This is not done automatically.
@denolfe Yes, I tried that, but what I get is "No migration to run". Is it because I miss I step when changing the payload config ? Do I have to explicitly start a migration before doing a change in the payload config ?
This part is unclear. I read the documentation carefully, but it doesn't provide much help 😦
So to recap, the workflow I tried after @denolfe's hint is the following:
1. Make changes to my Payload CMS configuration (e.g., add a field in a collection in
payload.config.ts
).
2. Commit and push these changes to my backend repository / Pull the changes on my live server.
3. Run
npm run build
on my server.
4. Run
npm run payload migrate
on my server to apply the changes to my database schema.
-> But I get a "No migration to run" message5. Finally, run
npm run serve
on my server
Is there something missing in this general workflow ? I even tried to empty the db to see if build/migrate would create the schema, but it didnt.
I'm obviously missing something... At what point in the process is the schema supposed to be built in the db ?
You are missing one part between 1 and 2. You need to run
payload migrate:create
to write the migration to a file.
Check that file in. This will then be detected when you run migrate.
@denolfe Great, thanks !
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.