Skip to content

Reviewing PRs with database changes

Ian Dunn edited this page May 12, 2016 · 3 revisions

PRs will sometimes need to make changes to the database. Reviewing those can be difficult because the diffs have so much noise, but these methods make it at least manageable.

Setup for both methods

  • Move the clean, original database to {database_name}_master
  • Checkout the PR branch
  • Import the new provision/{database_name}.sql file as {database_name}

In both methods, it'll be easier if you're only comparing the tables that have changes, rather than the entire database. You can revert any changes in tables that aren't relevant to the PR.

Summary method

This is the normal method, and works best when you just need to skim the changes to make sure they make sense and that nothing out of the ordinary is there.

  • mysqldump --opt --compact --skip-extended-insert -u root -proot {database_name} > {pr_number}.sql
  • mysqldump --opt --compact --skip-extended-insert -u root -proot {database_name}_master > master.sql

If the .sql files are small enough, you can just open them in a visual diff tool like DeltaWalker, but that becomes painful if they're larger than a couple megabytes.

In that case, run

diff master.sql {pr_number}.sql | split -b 1000000 - master_{pr_number}.diff-

...and manually review the split diffs in your favorite text editor.

props @atimmer

Detailed method

This works best in cases where it'd be advantageous for the diff tool to have knowledge of MySQL and/or you want to review the changes in detail.

The diff in this method is about 10x the size of the first method, though, so in some cases it might be easier to use first method and then manually compare in Sequel Pro when you run into occasional oddities.

  • sudo apt-get install mysql-utilities
  • mysqldbcompare --server1=root:root@localhost {database_name}_master:{database_name} --width=175 --run-all-tests --skip-row-count | split -b 5000000 - master_{pr_number}.diff-
Clone this wiki locally