<?xml version="1.0"?>
<!-- * define your project name -->
<project name="mysqlbuild" basedir=".">
 
    <description>
        Database build file 
 
        Please review property files to verify paths are correct before using!
 
        Available Tasks:
        - build.db.local - will drop all existing tables, create database and populate with test data
        - backup.local - dump local database
        - restore.local - load local database from dump file
        - copy-dev-to-local - copy development database to local instance
    </description>
 
    <!-- load additional tasks -->
    <taskdef resource="net/sf/antcontrib/antlib.xml" description="ANT Contib library"/>
    <taskdef name="query" classname="com.jera.anttasks.Query" description="I provide a secure password dialog"/>
 
    <property file="${user.name}.properties"/>
    <property file="build.properties"/>
 
    <target name="-set.password">
        <query name="mysql.password" password="true" />
    </target>
 
    <target name="buld.db.local" depends="-set.password">
        <echo>
            Creating new ${ant.project.name} database from script
        </echo>
        <drop-database server="local" database="${ant.project.name}"/>
        <sql driver="${db.driver}" url="${db.local.url}" userid="${db.local.un}" password="${mysql.password}" keepformat="true">
            <transaction src="dbscripts/credtrak.sql"/>
        </sql>
    </target>
 
    <target name="backup.local"  depends="-set.password" description="Dump local database to file">
        <echo>
            Creating dump of ${ant.project.name}
        </echo>
        <dump-database server="local" database="${ant.project.name}"/>
    </target>
 
    <target name="restore.local" depends="-set.password" description="Restore local database from dump file">
        <echo>
            Loading ${ant.project.name}
        </echo>
        <load-database server="local" database="${ant.project.name}"/>
    </target>
 
    <target name="copy-dev-to-local"  depends="-set.password" description="Copy development database to local">
        <dump-database server="development" filename="${ant.project.name}-dev-to-local.sql"/>
        <!--
        <drop-database server="local"/>
        <load-database server="local" filename="${ant.project.name}-dev-to-local.sql"/>
        -->
    </target>
 
 
 
<!-- MACRODEFS - DO NOT EDIT BELOW THIS LINE -->
    <macrodef name="load-database">
        <attribute name="server" default="local"/>
        <attribute name="database" default="${ant.project.name}"/>
        <attribute name="filename" default="${ant.project.name}-dump.sql"/>
        <sequential>
            <echo>
                Importing ${ant.project.name} on @{server} from @{filename}
                Running ${path.mysql}
            </echo>
            <exec executable="${path.mysql}/mysqldump" input="dbscripts/@{filename}">
                <arg value="--user=${db.@{server}.un}"/>
                <arg value="--password=${mysql.password}"/>
                <arg value="--host=${db.@{server}}"/>
                <arg value="--port=3306"/>
                <arg value="@{database}"/>
            </exec>
        </sequential>
    </macrodef>
 
    <macrodef name="dump-database">
        <attribute name="server" default="local"/>
        <attribute name="database" default="${ant.project.name}"/>
        <attribute name="filename" default="${ant.project.name}-dump.sql"/>
        <sequential>
            <echo>
                Creating dump of ${ant.project.name}  on @{server} to @{filename}
                Running ${path.mysql}
            </echo>
            <exec executable="${path.mysql}/mysqldump" output="dbscripts/@{filename}">
                <arg value="--user=${db.@{server}.un}"/>
                <arg value="--password=${mysql.password}"/>
                <arg value="--host=${db.@{server}}"/>
                <arg value="@{database}"/>
            </exec>
        </sequential>
    </macrodef>
 
    <macrodef name="drop-database" description="Drop database">
        <attribute name="server" default="local"/>
        <attribute name="database" default="${ant.project.name}"/>
        <attribute name="filename" default="${ant.project.name}-dump.sql"/>
        <sequential>
            <echo>
                Dropping @{database} (if exists) database on ${db.@{server}} using ${db.@{server}.url}
            </echo>
            <sql driver="${db.driver}" url="${db.@{server}.url}" userid="${db.@{server}.un}" password="${mysql.password}" keepformat="true">
                DROP DATABASE IF EXISTS @{database};
            </sql>
        </sequential>
    </macrodef>
 
</project>
/home3/thecrumb/public_html/wiki/data/pages/ant/database.txt · Last modified: 2010/11/11 12:16 by thecrumb
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki