jenkins the definitive guide

(Jeff_L) #1

Since this representation records the semantic nature of the change, Liquibase is capable of handling
both the schema updates and data migration associated with this change correctly.


Liquibase can also handle updates to the contents of your database, as well as to its structure. For
example, the following change set inserts a new row of data into a table:


<changeSet id="326" author="simon">
<insert tableName="country">
<column name="id" valueNumeric="1"/>
<column name="code" value="AL"/>
<column name="name" value="Albania"/>
</addColumn>
</changeSet>

Each changeset has an ID and an author, which makes it easier to keep track of who made a particular
change and reduces the risk of conflict. Developers can test their change sets on their own database
schema, and then commit them to version control once they are ready. The next obvious step is to
configure a Jenkins build to run the Liquibase updates against the appropriate database automatically
before any integration tests or application deployment is done, usually as part of the ordinary project
build script.


Liquibase integrates well into the build process—it can be executed from the command line, or integrated
into an Ant or Maven build script. Using Maven, for example, you can configure the Maven Liquibase
Plugin as shown here:


<project>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-plugin</artifactId>
<version>1.9.3.0</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

Using Liquibase with Maven this way, you could update a given target database to the current schema
using this plugin:


$ mvn liquibase:update

The default database connection details are specified in the src/main/resources/
liquibase.properties file, and might look something like this:


changeLogFile = changelog.xml
Free download pdf