Liquibase Hello

Liquibase hello-world

This is a simple hello-world style example for the Liquibase relational database changeset handler.

Trying it out

To try it out:

1sgit clone git://github.com/jave/liquibase-helloworld.git
2cd liquibase-helloworld
3mvn liquibase:update

The changelog file

A H2 database file /tmp/liquidhello.h2.db will be created.

Below is an example of what Liquibase changelog file can look like.

It defines two changesets, with ids 1 and 2.

Changeset 1 creates a table called test, with a column called name.

Changeset 2 adds a column to the table called test, called address.

 1
 2<?xml version="1.0" encoding="utf-8"?>
 3<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
 4		   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5		   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
 6
 7  <changeSet id="1" author="jave">
 8
 9    <createTable tableName="test">
10      <column name="id" type="int"/>
11      <column name="name" type="varchar(50)"/>
12    </createTable>
13  </changeSet>
14
15  <changeSet id="2" author="jave">
16    <addColumn  tableName="test">
17	<column name="address" type="varchar(255)"/>
18    </addColumn>
19  </changeSet>
20
21</databaseChangeLog>

The pom.xml file

The pom.xml file defines things like the jdbc url we need, and also the version of the liquibase plugin.

 1
 2<?xml version="1.0" encoding="utf-8"?>
 3<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4	 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5  <modelVersion>4.0.0</modelVersion>
 6  <groupId>se.verona.liquibasehello</groupId>
 7  <artifactId>liquibasehello</artifactId>
 8  <version>1.0-SNAPSHOT</version>
 9  <build>
10    <plugins>
11      <plugin>
12	<groupId>org.liquibase</groupId>
13	<artifactId>liquibase-maven-plugin</artifactId>
14	<version>3.0.0-rc1</version>
15	<configuration>
16	  <changeLogFile>src/main/resources/db-changelog.xml</changeLogFile>
17	  <driver>org.h2.Driver</driver>
18	  <url>jdbc:h2:/tmp/liquidhello</url>
19	</configuration>
20	<dependencies>
21	  <dependency>
22	    <groupId>com.h2database</groupId>
23	    <artifactId>h2</artifactId>
24	    <version>1.3.171</version>
25	  </dependency>
26	</dependencies>
27      </plugin>
28    </plugins>
29  </build>
30</project>