By Nazariy


2019-06-07 18:41:34 8 Comments

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!

2 comments

@Rick Hellewell 2019-06-07 22:30:35

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.

@MikeNGarrett 2019-06-07 20:10:44

There 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.

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] Multiple developers / editors working on a site in progress

3 Answered Questions

1 Answered Questions

[SOLVED] Access theme options in templates

1 Answered Questions

[SOLVED] Localhost keeps redirecting to live domain

  • 2017-02-17 06:26:05
  • Milan
  • 505 View
  • 1 Score
  • 1 Answer
  • Tags:   database

2 Answered Questions

[SOLVED] Staging sites, how do you manage synchronising updates in the DB?

1 Answered Questions

Theme Options - localhost to new url

1 Answered Questions

[SOLVED] Creating Theme Options Page

6 Answered Questions

2 Answered Questions

[SOLVED] Add a new checkbox in theme options

Sponsored Content