Let's say you are building a new theme on a staging site.
While you were building, the production database has changed due to new user registrations/orders.
So now the question becomes how do you upload a new theme together with all the theme database options to a production site without disrupting anything else.
I know you can use something like WP Migrate DB Pro to only push certain tables, but even then which tables to push.
I'm just curious how do people maintain a synced database between a production, staging, and localhost site?
Thank you in advance for any guidance!
Let's say you are building a new theme on a staging site.
While you were building, the production database has changed due to new user registrations/orders.
So now the question becomes how do you upload a new theme together with all the theme database options to a production site without disrupting anything else.
I know you can use something like WP Migrate DB Pro to only push certain tables, but even then which tables to push.
I'm just curious how do people maintain a synced database between a production, staging, and localhost site?
Thank you in advance for any guidance!
Share Improve this question asked Jun 7, 2019 at 18:41 NazariyNazariy 1313 bronze badges 2- Some hosts handle staging-to-prod and vice versa - varies widely by host. On most but not all hosts, you can use WP-CLI, though that may have a bit more of a learning curve. What tables to push really depends on the theme and how they store their options - it's worth checking with the theme author to find out what data is stored where, so you can just copy the files and that small portion of the database over. – WebElaine Commented Jun 7, 2019 at 19:02
- Related: wordpress.stackexchange/questions/99472/… – Jesse Nickles Commented Jan 19, 2023 at 14:45
2 Answers
Reset to default 2There are a number of options that depend on your level of comfort with code and the number of changes you need to make. There are also a number of ways to achieve the same result. You mention partial migrations. If you can do that, go with it. That's the fastest.
I'm going to cover how I would handle this. It's not the right or wrong answer, but just my perspective. This process assumes some potential downtime while you're doing the deployment. There are other options for high-availability websites that can be far more complex, so I won't cover those here.
Track your changes
While you're developing try to have any database changes in code if you can. For example, if you have custom fields, post types, taxonomies, make sure you have these registered as a part of the theme. Include default variables in here as well.
Create a migration script
For bigger changes, start a WP CLI script (or plugin) to roll out and roll back your migration. This is useful for importing new content, moving content, or altering taxonomies.
BACK UP YOUR DATA
Before you run anything, make sure you have a backup. Losing your work is tough, but losing customer data is detrimental.
Run everything on a staging environment
Once you're ready, set up a staging environment with your new code (from your dev environment) and your production database. You should do the minimum database changes required to get this set up (usually only search-replace). When you push this live the site will be in this state: new code without any database changes to support it.
From there, start your migration scripts and make sure everything executes smoothly. Make sure you haven't lost any data and that nothing is broken. Then run your roll back scripts to make sure you can undo everything you've done. Always test these scripts to make sure if something goes wrong you can get back to where you were quickly.
If you run into a problem, rerun this process until everything works without a hitch.
Repeat
Do the same thing on your production environment. You will probably want to put the site in maintenance mode while you're running these scripts to prevent any errors or user complaints.
If you just want to get the 'customization' stuff of a theme from one site to another (running the same theme), then there are Customization Export/Import plugins that will add that feature to your Theme Customization theme.
I've used "Customizer Import/Export" plugin with great success.