MySQL Team Development – Best Practices for Using Different MySQL Instances

MySQLteamteamwork

This may be a noob question but a colleague and I are working on a project. Some background about our situation is:

  • We control versions using a centralized git server inside our office.
  • We code in PHP, so we try our code offline in a local apache instance.
  • We use local MySQL instances at work.

Our client is a bit of a demanding person, and has changed the requirements more than twice. The main problem is that if we need to change something in the database, we have to make clean dumps on other servers (the other teammate's computer, the central server…, and the client's server of course) to make other instances work, too.

My question is, is there a way to synchronize our local databases (I don't care about the client's one at this moment) with git or another utility to make my colleague, the git server and my database be up to date when we push changes? If that is not possible, do you know of any better way to work with MySQL databases stored locally? Thanks in advance.

PS: Using only one central database is not a valid solution for us, as we test different features and have different elements stored there.

Best Answer

First thing you should always do on any project is automate the build, deployment and release processes.

This means in your case:

  1. Automate setting up the database from a clean slate with fresh DDL.
  2. Automate loading any default data into this fresh state DDL.
  3. Automate dumping any data out so that it can be reimported in a single step.
  4. Automate upgrading an existing schema with new DDL.
  5. Automate migration of data from the old schema to the new one if needed.

Make all this available as goals from your automated build scripts, so that you can in a single command line build, the code, configure the database.

Make installation of your code automated as well, RPM or Debian packages are a must here for Linux. Leverage the above scripts for update scenarios from within your package managers.

These can be done with anything ranging from bash scripts, to something like Maven with its plugins, either way it should not rely on platform specific GUI tools if at all possible. This is an extremely common problem domain, and there are great solutions in just about every possible language that you should be able to leverage specific to your environment.

If you don't see it, the recurring theme is automation. Only one person on your team should have to do he above tasks once, and everyone else can benefit from their work. Automation is a force multiplier. The smaller the team, the greater the ratio of the multiplier time wise.