Handle changes to the database in production

default discord avatar
unclaimed105212 months ago
4

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)

  • discord user avatar
    jacobsfletch
    12 months ago

    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/434


    MongoDB 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/287
  • default discord avatar
    unclaimed105212 months ago

    Sweet, thanks for helping out!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.