ganesh
ganesh

Reputation: 2599

How to run liquibase on linux system

I am working with Liquibase on Linux, does anyone know how to run the datbasechangelog.xml file from the Linux prompt step by step? And what's the idea behind databasechangelog and how it works?

Upvotes: 4

Views: 4354

Answers (1)

awied
awied

Reputation: 2698

For our projects, we have set up ant tasks to do this. So, for example, if you want to run the migrations, the ant file may look like the following:

ant-migrations.xml

<project name="Migrations" basedir="." default="update-database">
<property file="./liquibasetasks.properties" />

<path id="master-classpath" description="Master classpath">
    <fileset dir="..\lib">
        <include name="*.jar" />
    </fileset>
</path>

<target name="update-database">
    <fail unless="db.changelog.file">db.changelog.file not set</fail>
    <fail unless="database.url">database.url not set</fail>

    <fail unless="database.username">database.username not set</fail>
    <fail unless="database.password">database.password not set</fail>

    <taskdef resource="liquibasetasks.properties">
        <classpath refid="master-classpath"/>    
    </taskdef>

    <updateDatabase
            changeLogFile="${db.changelog.file}"
            driver="${database.driver}"
            url="${database.url}"
            username="${database.username}"
            password="${database.password}"
            promptOnNonLocalDatabase="${prompt.user.if.not.local.database}"
            dropFirst="false"
            classpathref="master-classpath"
    />

</target></project>

Make sure your liquibase jar file(s) are referenced in the classpath element.

The properties file contains the references that are particular to your environment:

liquibasetasks.properties

db.changelog.file=YOUR_MIGRATION_FILE.xml

#################################
## DB Settings
#################################
database.driver=
database.username=
database.password=
database.url=

Ok, so now we have the ant task set up and configured.. with all of that saved, you should be able to run the migration by typing the following at the command prompt:

linux>ant -f ant-migrations.xml update-database

Hope that helps!

Upvotes: 3

Related Questions