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

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.8"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.8
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.8.xsd">
</databaseChangeLog>



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



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.

Comments

Post a Comment

Popular posts from this blog

Converting Java Map to String

Difference between volatile and synchronized

Invoking EJB deployed on a remote machine