Details
Description
Adding a command that allows the DDLToDatabase task to drop all the tables in the specified database by issuing a bunch of drop table commands. This is very handy for us when we want to quickly clean out a database without dropping the entire database itself.
Example usage:
<target name="db.clean" description="Drops all tables and constraints in the target DB.">
<input addproperty="db.clean.confirm" message="Are you sure you wish to drop all tables in this DV_MASTER database: ${db.master.url} (${db.master.user}) and in this DV_REFERENCE database: ${db.reference.url} (${db.reference.user})? " validargs="y,n" />
<condition property="db.clean.abort">
<equals arg1="n" arg2="${db.clean.confirm}" />
</condition>
<fail if="db.clean.abort">Database clean aborted by user.</fail>
<db.clean.macro db.user="${db.master.user}" db.password="${db.master.password}" db.type="${db.master.type}" db.driver="${db.master.driver}" db.url="${db.master.url}" db.schema="${db.master.schema}" db.catalog="${db.master.catalog}" />
<db.clean.macro db.user="${db.reference.user}" db.password="${db.reference.password}" db.type="${db.reference.type}" db.driver="${db.reference.driver}" db.url="${db.reference.url}" db.schema="${db.reference.schema}" db.catalog="${db.reference.catalog}"/>
</target>
<macrodef name="db.clean.macro">
<attribute name="db.user" description="Database User Name" />
<attribute name="db.password" description="Database Password" />
<attribute name="db.type" description="Type of Database" />
<attribute name="db.driver" description="Classname of JDBC Driver" />
<attribute name="db.url" description="JDBC connection URL" />
<attribute name="db.schema" description="JDBC schema pattern" />
<attribute name="db.catalog" description="JDBC catalog pattern" />
<sequential>
<taskdef name="ddl_to_db" classpathref="ddlutils.classpath" classname="org.apache.ddlutils.task.DdlToDatabaseTask" />
<ddl_to_db databaseType="@
" validateXml="false" schemaPattern="@
{db.schema}" catalogPattern="@
{db.catalog}">
<database url="@
" driverClassName="@
{db.driver}" username="@
{db.user}" password="@
{db.password}" />
<dropAllTables />
</ddl_to_db>
</sequential>
</macrodef>