-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.xml
94 lines (81 loc) · 3.81 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<project name="demoformation-api" default="help" basedir=".">
<if>
<available file="${project.basedir}/build.local.properties" />
<then>
<property file="${project.basedir}/build.local.properties" />
</then>
</if>
<property file="${project.basedir}/build.properties" />
<target name="help" description="List available targets">
<exec executable="vendor/bin/phing"
passthru="true">
<arg value="-l"/>
</exec>
</target>
<!-- generate config -->
<target name="generate-config">
<copy todir="${project.basedir}/config"
overwrite="true">
<fileset dir="${project.basedir}/config">
<include name="**/*.local.php.dist" />
</fileset>
<mapper type="glob" from="*.local.php.dist" to="*.local.php" />
<filterchain>
<replacetokens>
<token key="db.host" value="${db.host}" />
<token key="db.port" value="${db.port}" />
<token key="db.dbname" value="${db.dbname}" />
<token key="db.username" value="${db.username}" />
<token key="db.password" value="${db.password}" />
</replacetokens>
</filterchain>
</copy>
</target>
<target name="setup-phinx" description="Setup Phinx configuration">
<echo message="Creating Phinx config file" />
<loadfile property="phinx.config" file="./phinx.yml.dist">
<filterchain>
<replacetokens>
<token key="env" value="${env}" />
<token key="db.host" value="${db.host}" />
<token key="db.port" value="${db.port}" />
<token key="db.dbname" value="${db.dbname}" />
<token key="db.username" value="${db.username}" />
<token key="db.password" value="${db.password}" />
</replacetokens>
</filterchain>
</loadfile>
<echo message="${phinx.config}" file="./phinx.yml" />
</target>
<target name="drop-db">
<echo file="./data/db/drop.sql">DROP DATABASE IF EXISTS `${db.dbname}`;</echo>
<pdosqlexec url="mysql:host=${db.host}" userid="root">
<transaction src="./data/db/drop.sql"/>
</pdosqlexec>
<delete file="${project.basedir}/data/db/drop.sql" quiet="true"/>
</target>
<target name="init-db" description="Create Database and Grants">
<echo file="${project.basedir}/data/db/create.sql">
CREATE DATABASE IF NOT EXISTS ${db.dbname};
GRANT USAGE ON *.* TO '${db.username}'@'%' IDENTIFIED BY '${db.password}';
GRANT UPDATE,CREATE,REFERENCES,ALTER,LOCK TABLES,CREATE VIEW,CREATE
ROUTINE,TRIGGER,INSERT,DELETE,DROP,INDEX,CREATE TEMPORARY TABLES,EXECUTE,SHOW VIEW,ALTER ROUTINE,SELECT ON
`${db.dbname}`.* TO '${db.username}'@'%';
</echo>
<pdosqlexec url="mysql:host=${db.host}" userid="root">
<transaction src="${project.basedir}/data/db/create.sql"/>
</pdosqlexec>
<delete file="${project.basedir}/data/db/create.sql" quiet="true"/>
</target>
<target name="db-migration" description="Update the database version">
<exec command="${phinx.bin} migrate -c phinx.yml --quiet" passthru="true"/>
</target>
<target name="show-env" description="Display environment vars">
<exec command="env" passthru="true"/>
<echo>DB HOST: ${db.host}</echo>
</target>
<target name="reset-db" description="Reset the Database" depends="drop-db, init-db"/>
<target name="setup"
description="Setup external dependencies and migrate data"
depends="show-env, generate-config, setup-phinx, db-migration"/>
</project>