Hello guys, I'm making a big website using PayloadCMS as backend. I'm not very far from finishing it, and I wanted to ask you a question about database changes.
-
So far whenever I want to make changes to the database (for example I change a field name from
userPage
to
userHasPage
), Payload will stop considering all the
userPage
named fields and from now on will only account for
userHasPage
. This makes all the data stored as
userPage
not accessible to the website. The best solution I found so far is to make a script that will change
userPage
to
userHasPage
on all the old records.
-
Is there some other method to do this? (My real question is if Payload can handle this process differently without me doing so much manual work, or it's fine to do the changes using a script)
Your pretty much spot on, right now you have to write your own migration scripts. But this is tried and tested and there are many examples out there to help get you 99% of the way there, namely this one:
https://github.com/payloadcms/payload/discussions/434MongoDB will keep your old fields in place without modifying your data after a schema change
In the future migrations will get exponentially easier, especially after we launch our adapter-style database pattern described here:
https://github.com/payloadcms/payload/discussions/287Sweet, thanks for helping out!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.