Use of version control system while programming software projects is a necessity these days. Be it a one-man army project or a project with a five member team, which requirements and scenarios changing every now and then maintaining previous versions does help. But, keeping database in version control system isn’t that popular because most of the time it’s taken for granted.
What most developers don’t realize is that just like the source files of a project, the values in database are also changing regularly. Thus, the need for maintaining the previous version of database arises. It not only helps you track changes, but also helps in sharing it with other members of the team.
In this article we’ll look into DBV, which is a database version control system written in PHP for maintaining database in MySQL. This isn’t a stand-alone version control system and requires assistance from a third party version control system like Git, SVN or Mercurial to ensure optimum synchronization of data with the team.
Installation to Get Started With DBV
You can get DBV from their website (http://dbv.vizuina.com/). The installer downloaded from the site need to be extracted into the concerned project directory and the folder needs to be renamed to “dbv”.
You can even opt for the alternative approach of cloning from Github.
In order to configure DBV, copy the “config.php.sample” file and rename it to “config.php”.
You basically need to update the first two sections.
Firstly, the values of “my_username”, “my_password”, “my_database” need to be substituted for the values in current database configuration.
* Database authentication information
* Authentication data for access to DBV itself
* Leave any of the two constants blank, authentication will be disabled
The first section was entirely about configuration of MySQL on your machine. In the second section, we’ll set the login details for dbv.
When you open the “gitignore” file, you’ll find the following information.
These are the files meant to be ignored by Git. But, if you and your team members share the database information, i.e., username, password, and database name, then you can do without the “config.php” file in “.gitignore”. If not then your team members need to create separate configuration file and exclude that form source control.
Moreover, a file named “data/meta/revision” needs to be added into “.getignore” file because this file contains information about local copy of the database. Since it might differ from your team members, therefore, you should exclude it from source control.
After completing the configuration process, add dbv into version control
git add dbv
git commit -m "add dbv into project"
What Needs To Be Tracked?
Before we began using dbv, let’s take a look at what changes need to be tracked. There are various changes to be put into source control; some of these changes are as follows:
new table row (default table data)
updated table row
deleted table row
Working with DBV
The following URL will help you run dbv from the browser:
If you have defined a virtual host, then you will get the following interface by accessing the URL.
This UI will display the tables you supplied in the “config.php” file and the ones that are currently in the database. In addition to this, there’s an ‘In DB’ field which specifies if the database still holds the table and an “On disk” field determines if the table is saved in the file system. This information notifies that you’re holding the latest copy of the database.
Make sure that if you make a change like creating a new table in the database, you need to commit it into the source control as well like export it to the disk. The exported tables get stored in the “data/schema” directory of dbv installation.
For instance, you don’t have a table named ‘tblinfo’ in your file system, and you create it. After exporting it to the disk you need to commit it to the version control system as well.
git add data/schema/tbltasks.sql
git commit -m "add tbltask table"
Now if your team members visit the dbv page http://localhost/your_project/dbv, they get the name of two new tables in the database, i.e., tblinfo and tbltasks. The tblinfo is present in the DB but, not on the disk, while tbltasks is present on the disk and not on the DB.
There will be 2 buttons “push to database” and “export to disk” to allow you to take necessary action with the respective table.
DBV offers an easy way to manage your database version control needs. You and your team can keep track of the changes made in your database quite easily. This is necessary when dealing with database of complex system that gets new value every now and then. Moreover, with the use of Git, you can easily share the changes with the rest of your team members hassle-free, ensuring that everyone has the latest copy of the database every time.