Spring Liquibase – DB Creation/Changes

Steps to Configure Spring Liquibase
– Dependency – pom.xml

<dependency>
        <groupId>org.liquibase</groupId>
	<artifactId>liquibase-maven-plugin</artifactId>
	<version>3.4.1</version>
</dependency>

– In ApplicationContext.xml Create bean of SpringLiquibase

<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
		<property name="dataSource" ref="dataSource" /><!--DataSource cofigs refs related to DB-->
		<property name="defaultSchema" value="${jdbc.schema.name}" /><!--DB schema name-->
		<property name="changeLog" value="classpath:dbchanges/db-changelog.xml" /><!--Configuration file for liquibase-->
	</bean>

– db-changelog.xml

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
	<changeSet author="taher.tinwala" id="1" context="pre-process-db-changes" >
         <sqlFile dbms="postgresql" encoding="utf8" endDelimiter="\nGO" path="/sql-files/project_v1/sqlchanges_1.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/>
    </changeSet>
    <changeSet author="java.hunter" id="2" context="pre-process-db-changes">
        <sqlFile dbms="postgresql" encoding="utf8" endDelimiter="\nGO" path="/sql-files/project_v1/sqlchanges_2.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/>
    </changeSet>      
</databaseChangeLog>

– We have to place sql files in project for above mentioned location(path attribute)

Advertisements
This entry was posted in Hibernate, Liquibase, Spring and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s