I'm using PHP 8 and MySQL without a framework. What's a good way to keep the database and CMS content in sync across environments? Is copying the database enough, or should I use seeders?
How do you move CMS data between local, test and production?
Answers
Separate schema changes from content. Put table, column and index changes in versioned migrations, then apply those migrations in each environment. Phinx is one option for PHP, or you can use SQL scripts with a table that records which migrations have run.
Seeders are handy for initial content or reference data that should be the same everywhere. They get awkward for content that editors keep changing, though. For that, an export and import workflow is easier to manage than treating every page as a seeder.
Reply to this answer
For refreshing local and test, a production database export is a straightforward option once those environments are set up. Sanitize user data where needed before using it outside production.
That's a refresh, not a two-way sync. It won't merge local changes into production, and a database copy alone may not include uploaded files.
Reply to this answer
Migrations plus seeders might be all you need if the content is mostly initial setup data. Keep them with the code and run them as part of setting up each environment. I'd avoid relying on manual database copies for routine changes.
Reply to this answer
Think about where content gets edited before picking a direction. Copying a local database to production can wipe out live changes, so I'd avoid using local as the source of production data.
If content is prepared in test, a targeted export and import could move it to production without replacing the whole database. You'll still need to decide what happens when the same content has changed in both places, and how associated files get transferred.
Reply to this answer
Add your answer
Answers are reviewed before publication.
PAUSE_before_printing:
Would exporting selected content as JSON make sense for moving it between environments?
~yes!but+not_yet:
Yes, that could work. The import needs a way to identify existing content and handle changes made in both places, rather than blindly creating duplicates or overwriting edits.