Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put MySQL database under version control?

People also ask

Can you version control a database?

Liquibase is an open-source, migration-based version control database solution. It relies on a changelog to track what changesets have been deployed to a database, and what additional changesets need to be applied to a database in order to migrate a database schema to a specific version.

How do I manage database versions?

The most basic method for managing database changes is to save the alter command in a script or set of scripts, and manage them in the exiting file-based version control. This guarantees a single repository that stores all the application component assets.

How do I use SQL version control?

Open SQL Server Management Studio and connect to a SQL Server instance. Right-click on your database in the Object Explorer pane and select "Connect to Version Control". This will open the "Connect Database to Version Control" dialog. Copy the https repository path from GitHub and paste it into VersionSQL.


Note that recently (December 2012), you have another option: DBV (DataBase Version)

It is based on this Github project, and is a database version control web application featuring schema management, revision scripts, and more.

database schema


Whenever you make changes to your database, you should save those changes in a migration, that you can then later on run on other servers at the same time you update your code. But you basically got the right idea. You can write some tools to make it more automated; for example version each file, and then create a table like migration_version in your database, which will contain the current version of the database. You can then create a migrate script that will run all the migrations required to get the database up-to-date.

Note that if you want bi-directional db versioning (so that you can revert back to previous db version too), you need to write the required queries for that too for each version.

There are also some tools that can aid you in writing the migrations, such as MySQLdiff


Check out

Liquibase

http://www.liquibase.org/quickstart

The idea is this:

All database changes are stored in a human readable yet trackable form and checked into source control. - Liquibase.org front page

This is a fantastic piece of software that allows you to version your database, in roughly the same process as the top rated answer, except this wheel has already been written and is ready to roll. I use it at work, it's a fantastic solution. Implement it yourself if you want to learn how it works, but Liquibase works great if you want a tool to get things done.


You can use the MySQL Workbench tool.

The file generated with the modeling tool could esaly be saved under SVN. The tool allows you to synchronise your database with the model in bidirectionnal way.