Suggestions for syncing local / prod databases

default discord avatar
katie.lewis10 months ago
1

Hi! If we are hosting payload ourselves are there any suggestions for how to manage publishing development data to a production environment? In our use case, we are planning to build our company website on top of payload cms but we would want to be able to make modifications to the website locally and then publish changes once finished (schema and data). I couldn't find any documentation on the recommended way to handle this process? I was thinking we may need to write a script to do a mongodump / mongorestore but if there is a better way, I'm keen to hear it! Cheers

  • default discord avatar
    notchr10 months ago

    @katie.lewis Hey Kate, good morning



    I think it varies depending on your setup, and it's overall an opinionated topic



    But I'm happy to share my scenario at work



    We have a public facing website that uses Payload to update content.



    When we setup the local dev enviornment, we decided that we would have two mongo databased setup on the server, one for dev and one for prod



    This way, when we make payload changes in our dev enviorment, we don't have to worry about migrating data to the database



    Then, once we make some edits in our local dev enviorment, I have a script that handles our "CD", but it's pretty hacky



    Typically, you'd have a clean continuous deployment setup in your repository, but I don't



    I run a shell script that handles the uploading of new files



    That shell script looks like...



    pscp.exe -pw redacted -r -batch ./client/dist root@myserver:/var/www/example.com/client
    pscp.exe -pw redacted -r -batch ./payload/dist root@myserver:/var/www/example.com/payload
    pscp.exe -pw redacted -r -batch ./payload/build root@myserver:/var/www/example.com/payload


    Again, I chose to use pscp, which is a Windows CLI tool that does some things like ssh transfers, etc



    But I copy over my client dist files (public site), and both my payload dist and payload build folders to their respective directories



    That only takes a few seconds to complete (after we build the production files)



    The last thing I do after, is I restart my pm2 process, pm2 is managing our payload instance on the server so that it can be easily restarted



    PM2 can take a startup file, this is convinient if your pm2 instance somehow isnt able to recover its processes



    You make a file on your server, in this case

    ecosystem.config.js


    Mine looks like....



    module.exports = {
      apps: [{
        name: "payload",
        cwd: "/var/www/example.com/payload",
        script: "npm",
        args: "run serve"
      }, // Other things to run in the bg
      ]
    }


    You can start the process listed via



    pm2 start ecosystem.config.js


    And then any time you want to restart your payload app going forward, just type



    pm2 restart all


    So to review - build your prod files, run the shell script, run the pm2 restart command on the server



    and BOOM! easy deployments



    Note: again there are 1000 ways to deploy, and this is just one that works for our needs

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.