Databator

Database versioning

Getting Started Guide

Index

What is Databator?
Creating a new project
Adding a new version
Updating the database
Backup the database
Restore and Update the database
Commiting your changes to a code repository
Working in branches
Merging branches

What is Databator?

Databator is a tool that helps you manage the versioning of your database. It is based on the method described here: http://www.vladhorby.com/Blog/post/2009/11/17/A-simple-and-tool-free-way-for-database-versioning-%28I%29.aspx.

Creating a new project

Databator works for existing and new database projects. If you have an existing database, wou will be able to use the actual structure as "version zero" and manage your updates after this point.

To create a new Databator project, start Databator and click "New Project".

Select the path and file name you want for the project. Note that the path will be used as root for the project files and directories. After you click "OK" you will get a structure similar to this one:

The initial project structure also comes with the version 1 - the creation of the Version table, used for version tracking.

Adding a new version

To add a change for the database, click "Add new", above the versions list. The version number is assigned automatically and the branch name is set to "Local". Write a comment desctibing the change in the "Comments" section and place your script in the "Update script" section.

To be able to rollback to an earlier version, you must fill the "Rollback script", undoing (if possible) your change.

Click the "Save" inside the version tab to commit your changes to the files. This does not apply your changes to the database.

Updating the database

To update your database you must run the UpdateDB.bat script found in the root project folder, passing the server and database name. Note that your Windows user must have sysadmin rights in the database server. The update only applies the newer changes to the database (no need to worry about running the same script twice).

Backup the database

You can realize a backup to preserve your data and use it as a starting point for a restore. To backup your database you must run the BackupDB.bat script found in the root project folder, passing the server, database name and the relative path to the BAK file to be created (will overwrite existing one).

Restore and Update the database

If you want a clean start or to use different test data, you can always restore and bring the database up to date, starting from a specific backup. To restore your database you must run the RestoreDB.bat script found in the root project folder, passing the server, database name and the relative path to the BAK file. The update only applies the newer changes to the database (no need to worry about running the same script twice).

Commiting your changes to a code repository

You can add your Databator project folder to a code repository like Subversion. The following explanations assumes that you have your repository set up.

Before commiting your changes, you must execute an svn update to make sure that your working copy is up to date. After executing the update, click "Refresh" to reload the available versions from the file system. Let's assume that a colleague has already commited a version numbered "2":

To fix this, you can click "Move local overlapping versions". This rearranges your local version "2" to become "3".

You can restore your database and run the appropriate tests to ensure that there  is no conflict between your change and the one made by your colleague. When you are ready to commit, click "- Local" to remove the "_Local" suffix from the script files.

You can now execute an svn commit.

Working in branches

While you are working in a branch, set the branch name in the "Branch" section. When adding a new version, the branch name will be set automatically.

When commiting / updating to the branch you can apply the same activities as in Commiting your changes to a code repository.

Merging branches

When realizing a merge you might find that some version numbers have already been "taken" on the trunk.

To correct this, the same process applies as for local versions - the versions from the branch "move" to the end:

Before commiting, you must remove the branch name suffix from the file names, by clicking "- Branch".

You can now execute an svn commit.