-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphingDBTasks.xml
148 lines (135 loc) · 6.17 KB
/
phingDBTasks.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Phing include file for database tasks
- Author: Eric Vought
- 2015-01
- License: MIT (http://opensource.org/licenses/MIT)
-->
<!--
The MIT License
Copyright 2015 evought.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<project name="vctdbtasks" basedir=".">
<property name="vcardtools.sql.dir"
value="${phing.dir.vctdbtasks}/src/sql"/>
<property name="vcardtools.migrations.dir"
value="${vcardtools.sql.dir}/migrations"/>
<!-- database properties for testing -->
<property file="db.properties"/>
<filterchain id="vcardtools.db.unittest.filterset">
<replacetokens begintoken="@" endtoken="@">
<token key="vcardtools.db.unittest.user"
value="${vcardtools.db.unittest.user}"/>
<token key="vcardtools.db.unittest.host"
value="${vcardtools.db.unittest.host}"/>
<token key="vcardtools.db.unittest.passwd"
value="${vcardtools.db.unittest.passwd}"/>
<token key="vcardtools.db.unittest.dbname"
value="${vcardtools.db.unittest.dbname}"/>
<token key="vcardtools.db.unittest.dsn" value="${vcardtools.db.unittest.dsn}"/>
</replacetokens>
</filterchain>
<filterchain id="vcardtools.db.devel.filterset">
<replacetokens begintoken="@" endtoken="@">
<token key="vcardtools.migrations.dir"
value="${vcardtools.migrations.dir}"/>
<token key="vcardtools.db.devel.user"
value="${vcardtools.db.devel.user}"/>
<token key="vcardtools.db.unittest.host"
value="${vcardtools.db.unittest.host}"/>
<token key="vcardtools.db.devel.passwd"
value="${vcardtools.db.devel.passwd}"/>
<token key="vcardtools.db.unittest.dbname"
value="${vcardtools.db.unittest.dbname}"/>
<token key="vcardtools.db.unittest.dsn"
value="${vcardtools.db.unittest.dsn}"/>
</replacetokens>
</filterchain>
<target name="dbconfig"
description="Substitute macros to create needed db configuration files">
<copy file="${project.basedir}/database.php.in" toFile="${project.basedir}/database.php">
<filterchain refid="vcardtools.db.unittest.filterset"/>
</copy>
<copy file="${project.basedir}/phinx.yml.in" toFile="${project.basedir}/phinx.yml">
<filterchain refid="vcardtools.db.devel.filterset"/>
</copy>
</target>
<!-- Task to create a minimal-permissions user for unit testing.
- It shold be possible to run this before or after createUnitDB as long as
- it happens before tests are run.
- This is separated out and not run automatically because
- 1) it need not be done more than once per database install, and
- 2) the development user credentials may not have permission to create
- users in some environments.
- In the latter case, the unit test user will need to be created
- out-of-band and its credentials put into the user-specific
- properties file. As a worst-case, the same credentials can be used for
- both "development" and "unit-test" purposes, but, as a principle,
- it is best to run tests with the minimal permissions necessary to avoid
- introducing permission-related errors in a production environment.
-->
<target name="createUnitDBUser" depends="dbconfig"
description="Create the DB user for unit testing using the development DB credentials">
<pdosqlexec
url="${vcardtools.db.unittest.dsn}"
userid="${vcardtools.db.devel.user}"
password="${vcardtools.db.devel.passwd}"
autocommit="true">
CREATE USER '${vcardtools.db.unittest.user}'@'${vcardtools.db.unittest.host}'
IDENTIFIED BY '${vcardtools.db.unittest.passwd}';
</pdosqlexec>
</target>
<target name="createUnitDB" depends="dbconfig"
description="Create the database for unit testing">
<pdosqlexec
url="${vcardtools.db.unittest.dsn}"
userid="${vcardtools.db.devel.user}"
password="${vcardtools.db.devel.passwd}"
autocommit="true">
CREATE DATABASE ${vcardtools.db.unittest.dbname};
GRANT SELECT, INSERT, UPDATE, DELETE on ${vcardtools.db.unittest.dbname}.*
TO '${vcardtools.db.unittest.user}'@'${vcardtools.db.unittest.host}';
</pdosqlexec>
</target>
<target name="migrateDevelopment" depends="dbconfig"
description="Database Migrations for development environment">
<!-- execute phinx in migrate mode -->
<exec command="${vendor.bin.dir}/phinx migrate"
checkreturn="true"
passthru="true"
/>
</target>
<target name="rollbackDevelopment" depends="dbconfig"
description="Roll back database migrations for development environment">
<!-- execute phinx in migrate mode -->
<exec command="${vendor.bin.dir}/phinx rollback"
checkreturn="true"
passthru="true"
/>
</target>
<target name="dropUnitDB" depends="dbconfig"
description="Create the database for unit testing">
<pdosqlexec
url="${vcardtools.db.unittest.dsn}"
userid="${vcardtools.db.devel.user}"
password="${vcardtools.db.devel.passwd}"
autocommit="true">
DROP DATABASE ${vcardtools.db.unittest.dbname};
</pdosqlexec>
</target>
</project>