Syncing content


#1

I’m looking to use Cockpit for my next project, I was just wondering what is the best way to sync content between local / staging / production?

For example let’s say my website is live and I wish to add some new fields, I will first create these fields on local and also add the data in, I will then test and make sure I am happy with the changes. Then I will want to push these updates to staging, but I don’t want to repeat the field creation and data input.

At the same time, the client has made some changes on staging which I now need to pull down. So in other words I need to do a data sync. What would be the best way to do this?


#2

If you are talking on the structure of the collections and not contents (collection entries), you just need to sync the /storage/collections folder, you can for example use git for that. You can also look to the helpers addon, I’m providing there a very simple mechanism to store the collection structures in an addon and then install using the cockpit cli commmand.

If it is for syncing content you need to build your sync addon, that can be tricky, if the live site is not used to edit contents should be simpler, as it will be one way sync, for that case you can build something like:

  1. Have a data structure (queue) that stores content type, id and timestamp of last sync
  2. Every time a content is updated on stage, add it to the queue
  3. Have a deploy page that lists the contents to sync
  4. On the deploy page provide a publish action, when triggered it will create/update the contents in the live site using cockpit api

but keep in mind that you may need to deal with errors, validation of content structures, etc…