My favorites | Sign in
Project Logo
                
Search
for
Updated Oct 18, 2009 by gra...@tackley.net
Labels: Featured
UsingTheAntInterface  
How to invoke dbdeploy from ant

In the supplied distribution is an example ant file, examples/build.xml. You can probably just get started using that.

Here a step by step instructions.

Classpath and taskdef

You need to declare the dbdeploy task to ant. The dbdeploy task needs to talk to your database, so the task classpath should also include the database drivers, e.g.

    <path id="hsql.classpath">
        <fileset dir="lib">
            <include name="hsqldb*.jar"/>
        </fileset>
    </path>

   <path id="dbdeploy.classpath">
        <!-- include the dbdeploy-ant jar -->
        <fileset dir="lib">
            <include name="dbdeploy-ant-*.jar"/>
        </fileset>

        <!-- the dbdeploy task also needs the database driver jar on the classpath -->
        <path refid="hsql.classpath" />

    </path>

Then, you can declare the dbdeploy task:

    <taskdef name="dbdeploy" classname="com.dbdeploy.AntTarget" classpathref="dbdeploy.classpath"/>

Invoking dbdeploy

Next include a call to the dbdeploy task in the relevant database target, for example:

    <dbdeploy
        driver="org.hsqldb.jdbcDriver"
        url="jdbc:hsqldb:hsql://localhost/xdb"
        userid="sa"
        password="s3cur1ty"
        dir="db\deltas"
    />

The parameters are as follows:

Attribute Description Required
driver Specifies the jdbc driver Yes
url Specifies the url of the database that the deltas are to be applied to. Yes
userid The ID of a dbms user who has permissions to select from the schema version table. Yes
password The password of the dbms user who has permissions to select from the schema version table. Yes
dir Full or relative path to the directory containing the delta scripts. Yes
delimiterDelimiter to use to separate scripts into statements, if dbdeploy will apply the scripts for you i.e. you haven't specified outputfile. Default ;No
delimitertypeeither normal: split on delimiter wherever it occurs or row only split on delimiter if it features on a line by itself. Default normal.No
outputfile The name of the script that dbdeploy will output. Include a full or relative path. You only need to use this if you use dbdeploy in script mode - see GeneratingAndCustomisingScriptsNo
dbms The target dbms. You only need to use this if you use dbdeploy in script mode - see GeneratingAndCustomisingScripts No
undoOutputfile The name of the undo script that dbdeploy will output. Include a full or relative path. No
lastChangeToApply The highest numbered delta script to apply. No
changeLogTableName The name of the changelog table to use. Useful if you need to separate DDL and DML when deploying to replicated environments. If not supplied defaults to "changelog"No

Note that delimiter and delimitertype are intentionally the same as the same parameters provided by the ant sql task.


Comment by timcoffman0519, May 12, 2009

The version that I'm using (3.0M1) uses the attribute "lastChangeToApply" instead of "maxNumberToApply".

Comment by gra...@tackley.net, Sep 14, 2009

Thanks - the docs were wrong, updated now

Comment by tfnico, Oct 05, 2009

Still no dbms support for postgres? I see that it was discussed in http://groups.google.com/group/db-deploy-users/browse_thread/thread/dd958110e5e5c3f8 - but no patch has been applied, as far as I can see.

Comment by gra...@tackley.net, Oct 11, 2009

tfnico: thanks for raising  issue 26  and sending a patch. pgsql is now supported and on the list above :)

Comment by cloudforge, Oct 17, 2009

How do you supply classpathref to dbdeploy task so it can find DB drivers ?

Comment by gra...@tackley.net, Oct 18, 2009

@cloudforge: you need to do it in the taskdef, not when you invoke dbdeploy. So in the example above:

<taskdef name="dbdeploy" classname="com.dbdeploy.AntTarget" classpathref="dbdeploy.classpath"/>

notice that dbdeploy.classpath has got both the dbdeploy jar and the database jar within in it.


Sign in to add a comment
Hosted by Google Code