Skip to content

Instantly share code, notes, and snippets.

@garyhodgson
Created January 21, 2010 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garyhodgson/283329 to your computer and use it in GitHub Desktop.
Save garyhodgson/283329 to your computer and use it in GitHub Desktop.
dbDriver = 'org.hsqldb.jdbcDriver'
dbUrl = 'jdbc:hsqldb:file:db/testdb;shutdown=true'
path ( id:'dbdeployClasspath' )
{
fileset( dir:'..' , includes:'dbdeploy-ant-*.jar' )
}
path ( id:'hsqlClasspath' )
{
fileset( dir:'.' , includes:'hsqldb*.jar' )
}
ant.taskdef ( name:'dbdeploy' , classname:'com.dbdeploy.AntTarget', classpathref:'dbdeployClasspath')
target( default:'' )
{
depends(clean, updateDatabase)
}
target( clean:'clean' )
{
depends(dropAndCreateDatabase, createChangelogTable)
}
target( dropAndCreateDatabase:'drop and create database' )
{
ant.delete( dir:'db', failonerror:false )
mkdir ( dir:'db' )
}
target( createChangelogTable:'create changelog table' )
{
ant.sql( driver:"${dbDriver}", url:"${dbUrl}", userid:'sa', password:'', classpathref:'hsqlClasspath' )
{
fileset(file:'../scripts/createSchemaVersionTable.hsql.sql')
}
}
target( updateDatabase:'generate a sql upgrade script' )
{
/*
if you don't specify an output file, dbdeploy will apply the changes for you
you may need to specify delimiter and delimitertype for your scripts to be split properly - these
work the same as in the ant sql task, see http://ant.apache.org/manual/CoreTasks/sql.html
*/
dbdeploy( driver:"${dbDriver}", url:"${dbUrl}", userid:'sa', password:'', dir:'.')
}
target( updateDatabaseAndApplyAsSeparateStep:'generate a sql upgrade script' )
{
dbdeploy( driver:"${dbDriver}", url:"${dbUrl}", userid:'sa', password:'', dir:'.', outputfile:'output.sql', undoOutputfile:'undo.sql', dbms:'hsql')
ant.sql( driver:"${dbDriver}", url:"${dbUrl}", userid:'sa', password:'', classpathref:'hsqlClasspath' )
{
fileset(file:'output.sql')
}
}
target( dumpTables:'dump tables' )
{
ant.sql( driver:"${dbDriver}", url:"${dbUrl}", userid:'sa', password:'', classpathref:'hsqlClasspath', print:true )
{
transaction("select * from changelog;")
transaction("select * from test;")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment