Wednesday, April 1, 2009

Liquibase Incremental Database Changes

LiquiBase is used for managing, tracking and applying database changes. It uses XML file for storing incremental changes to data base.These xml file stores both
Database structures(DDL) and codes.LiquiBase is an open source (LGPL) Library

The following are some of the features which attract LiquiBase a lot

1) It is Open Source
2) It is Database independent
3) Supports rolling back changes
4) Supports merging of changes from multiple developers

The XML file which contains input to Liquibase is called databaseChangeLog File.

The following is a example of a empty databaseChangeLog file


The following fragment is a changeset, the following changeset defines a table called USERS with three columns.
  <changeSet author="Sidd" id="1.01">
          <createTable tableName="Users" >
            <column name="UsersID" type="BIGINT">
                    <constraints nullable="false" primaryKey="true" primaryKeyName="PK_Users"/>
             <column name="USERNAME" type="VARCHAR(20)">
                    <constraints nullable="false"/>
         <column name="USEREMAIL" type="VARCHAR(20)">
                <constraints nullable="false"/>

Liquibase can take this database changelog and create table automatically.

Getting started with LiquiBase takes four steps:

  1. Create a database change log file.
  2. Create a change set inside the change log file.
  3. Run the change set against a database via the command line or a build script.
  4. Verify the change in the database.

We can run Liquibase in two ways One is by firing commands from the console , or we can Use  Ant Tasks provided by Liquibase and call those task from Ant Build.
In the next post I will write how to work with Ant and Liquibase , probably with a example.

1 comment :