13

Currently i use a dump script and commit the database to the git repo. --skip-extended-insert --skip-comments --skip-dump-date means that a diff can give me a fair idea of what has changed, but it all falls down if I try to merge.

The WP_SITEURL, WP_HOME and all the other places wordpress stores full URLs need updating when importing to another host (testing,staging,production)

Is anyone using a better method?

Main issues:

  • Wordpress stores full URLs all through the database (non-portable)
  • Lots of other, non-relevant records change
    • auto_increment values (i just strip these out, but have run into ID issues)
    • timestamps (can also strip out, potentially)
    • transient* records ... no idea what to do with them

A process that created timestamped migrations, with only the things added or removed, would be ideal... but i'm not sure if it's even possible?

3
  • Do you want to version all data changes or only changes in structure? and that is your real BUSINESS-TASK? Commented Feb 14, 2014 at 6:31
  • When making changes to CMS's like wordpress, there are often content and configuration (DB data) changes along with logic (code) changes. I would like to be able to version both. Structure changes would be a good start ... BUSINESS TASK: client asks for new widget. Install plugin on staging server, commit to repo -> Configure plugin and add sample content -> once approved, pull code changes to production, then manually make same data changes in production admin. Commented Mar 1, 2014 at 0:27
  • 1
    @JacobDorman I'm trying to solve this exact same problem. Have you worked something out yet? After some research I'm starting to think some custom plugin that creates a specific update script is in order (probably to export only configuration changes such as installed plugins, and configuration options -- and not necessarily posts, categories, and content in general). Would love to hear if you have any other ideas. Commented Sep 9, 2014 at 0:43

2 Answers 2

6

Here are two possible solutions, both of these are actually generic MySQL version control tools but can be adapted to your workflow:

dbv.php

This tool creates "migrations", which are basically SQL scripts, from the changes detected on the database. These scripts are stored in a local directory and thus can be commited to your current VCS (git, for example).

It's used through a PHP web interface.

DBVC

Fundamentally similar to the previous tool, this is based on a command line interface. It's configured through a json file. The main difference is that it doesn't auto-generate the migration files.

There's a pending issue to integrate this with the previous similar, so that's something to look for.

Wordpress Plugins

Some plugins that could aid in the creation of a repeatable workflow:

5
  • dbvc looks like the kind of tool I've been looking for. thanks! Commented Sep 11, 2014 at 7:31
  • 1
    I'm glad it helped. I just found another interesting tool,it hasn't been updated in a while, but it might be worth to take a loot at: github.com/idler/MMP Commented Sep 11, 2014 at 15:10
  • @JacobDorman With DBVC, are you able to successfully merge DB changes from different environments? I have built a strategy of my own, but does DBVC produce the update files or do you have to use something like mysqldiff between SQL dumps? I can't image this tool being useful unless it helps produce SQL differences that are actually comparable, especially INSERT statement parameters on separate lines... although I suppose a file could be edited to deal with that... Commented Feb 27, 2016 at 15:57
  • @SpencerWilliams I didn't end up using DBVC (and haven't used mysqldiff) but still add db dumps to version control... I don't really see them as mergeable in most cases, but diffing using beyond compare can help highlight changes and issues. Commented Feb 28, 2016 at 10:16
  • @victor I checked out MMP. It does schema changes, but not data diffs / inserts. Commented Aug 19, 2016 at 19:01
4

I'm doing this on MYSQL.

It puts all the tables schema and data into their own file so I can easily see what has changed.

Unlike most of the other solutions in this thread this solution gets the data, which is important for a CMS.

This solution doesn't use any tools, just a command line script.

edit: I found my older code had a bug where import order was important. taking off the --compact flag fixes the bug.

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     echo exporting $x
     mysqldump -u root -ppassword --skip-add-drop-table --skip-add-locks --skip-disable-keys --skip-set-charset --extended-insert=FALSE --replace --skip-dump-date dbname $x > "./db/$x.sql"
done

Older code

for x in `mysql --skip-column-names -u root -ppassword dbname -e 'show tables;'`; do
     mysqldump -u root -ppassword --compact --extended-insert=FALSE --replace dbname $x > "./db/$x.sql"
done

and here is how to import

for x in `ls ./db/*.sql`; do
     echo importing $x
     mysql -pdbpassword dbname --force < $x
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.