1 |
<?php
|
2 |
/*
|
3 |
* $Id: Process.php 1080 2007-02-10 18:17:08Z jwage $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.org>.
|
20 |
*/
|
21 |
|
22 |
/**
|
23 |
* Doctrine_Migration_Process
|
24 |
*
|
25 |
* @package Doctrine
|
26 |
* @subpackage Migration
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
28 |
* @link www.phpdoctrine.org
|
29 |
* @since 1.0
|
30 |
* @version $Revision: 1080 $
|
31 |
* @author Jonathan H. Wage <jwage@mac.com>
|
32 |
*/
|
33 |
class Doctrine_Migration_Process
|
34 |
{
|
35 |
/**
|
36 |
* getConnection
|
37 |
*
|
38 |
* @param string $tableName
|
39 |
* @return void
|
40 |
*/
|
41 |
public function getConnection($tableName)
|
42 |
{
|
43 |
return Doctrine::getConnectionByTableName($tableName);
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
* processCreatedTables
|
48 |
*
|
49 |
* @param string $tables
|
50 |
* @return void
|
51 |
*/
|
52 |
public function processCreatedTables($tables)
|
53 |
{
|
54 |
foreach ($tables as $table) {
|
55 |
$conn = $this->getConnection($table['tableName']);
|
56 |
|
57 |
$conn->export->createTable($table['tableName'], $table['fields'], $table['options']);
|
58 |
}
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
* processDroppedTables
|
63 |
*
|
64 |
* @param string $tables
|
65 |
* @return void
|
66 |
*/
|
67 |
public function processDroppedTables($tables)
|
68 |
{
|
69 |
foreach ($tables as $table) {
|
70 |
$conn = $this->getConnection($table['tableName']);
|
71 |
|
72 |
$conn->export->dropTable($table['tableName']);
|
73 |
}
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
* processRenamedTables
|
78 |
*
|
79 |
* @param string $tables
|
80 |
* @return void
|
81 |
*/
|
82 |
public function processRenamedTables($tables)
|
83 |
{
|
84 |
foreach ($tables as $table) {
|
85 |
$conn = $this->getConnection($table['newTableName']);
|
86 |
|
87 |
$conn->export->alterTable($table['oldTableName'], array('name' => $table['newTableName']));
|
88 |
}
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
* processAddedColumns
|
93 |
*
|
94 |
* @param string $columns
|
95 |
* @return void
|
96 |
*/
|
97 |
public function processAddedColumns($columns)
|
98 |
{
|
99 |
foreach ($columns as $column) {
|
100 |
$conn = $this->getConnection($column['tableName']);
|
101 |
|
102 |
$options = array();
|
103 |
$options = $column['options'];
|
104 |
$options['type'] = $column['type'];
|
105 |
|
106 |
$conn->export->alterTable($column['tableName'], array('add' => array($column['columnName'] => $options)));
|
107 |
}
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
* processRenamedColumns
|
112 |
*
|
113 |
* @param string $columns
|
114 |
* @return void
|
115 |
*/
|
116 |
public function processRenamedColumns($columns)
|
117 |
{
|
118 |
foreach ($columns as $column) {
|
119 |
$conn = $this->getConnection($column['tableName']);
|
120 |
|
121 |
$columnList = $conn->import->listTableColumns($column['tableName']);
|
122 |
if (isset($columnList[$column['oldColumnName']])) {
|
123 |
$conn->export->alterTable($column['tableName'],
|
124 |
array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'],
|
125 |
'definition'=>$columnList[$column['oldColumnName']]))));
|
126 |
}
|
127 |
}
|
128 |
}
|
129 |
|
130 |
/**
|
131 |
* processChangedColumns
|
132 |
*
|
133 |
* @param string $columns
|
134 |
* @return void
|
135 |
*/
|
136 |
public function processChangedColumns($columns)
|
137 |
{
|
138 |
foreach ($columns as $column) {
|
139 |
$conn = $this->getConnection($column['tableName']);
|
140 |
|
141 |
$options = array();
|
142 |
$options = $column['options'];
|
143 |
$options['type'] = $column['type'];
|
144 |
|
145 |
$conn->export->alterTable($column['tableName'], array('change' => array($column['columnName'] => array('definition' => $options))));
|
146 |
}
|
147 |
}
|
148 |
|
149 |
/**
|
150 |
* processRemovedColumns
|
151 |
*
|
152 |
* @param string $columns
|
153 |
* @return void
|
154 |
*/
|
155 |
public function processRemovedColumns($columns)
|
156 |
{
|
157 |
foreach ($columns as $column) {
|
158 |
$conn = $this->getConnection($column['tableName']);
|
159 |
|
160 |
$conn->export->alterTable($column['tableName'], array('remove' => array($column['columnName'] => array())));
|
161 |
}
|
162 |
}
|
163 |
|
164 |
/**
|
165 |
* processAddexIndexes
|
166 |
*
|
167 |
* @param string $indexes
|
168 |
* @return void
|
169 |
*/
|
170 |
public function processAddedIndexes($indexes)
|
171 |
{
|
172 |
foreach ($indexes as $index) {
|
173 |
$conn = $this->getConnection($index['tableName']);
|
174 |
|
175 |
$conn->export->createIndex($index['tableName'], $index['indexName'], $index['definition']);
|
176 |
}
|
177 |
}
|
178 |
|
179 |
/**
|
180 |
* processRemovedIndexes
|
181 |
*
|
182 |
* @param string $indexes
|
183 |
* @return void
|
184 |
*/
|
185 |
public function processRemovedIndexes($indexes)
|
186 |
{
|
187 |
foreach ($indexes as $index) {
|
188 |
$conn = $this->getConnection($index['tableName']);
|
189 |
|
190 |
$conn->export->dropIndex($index['tableName'], $index['indexName']);
|
191 |
}
|
192 |
}
|
193 |
|
194 |
/**
|
195 |
* processCreatedConstraints
|
196 |
*
|
197 |
* @param string $constraints
|
198 |
* @return void
|
199 |
*/
|
200 |
public function processCreatedConstraints($constraints)
|
201 |
{
|
202 |
foreach ($constraints as $constraint) {
|
203 |
$conn = $this->getConnection($constraint['tableName']);
|
204 |
$conn->export->createConstraint($constraint['tableName'], $constraint['constraintName'],
|
205 |
$constraint['definition']);
|
206 |
}
|
207 |
}
|
208 |
|
209 |
/**
|
210 |
* processDroppedConstraints
|
211 |
*
|
212 |
* @param string $constraints
|
213 |
* @return void
|
214 |
*/
|
215 |
public function processDroppedConstraints($constraints)
|
216 |
{
|
217 |
foreach ($constraints as $constraint) {
|
218 |
$conn = $this->getConnection($constraint['tableName']);
|
219 |
$conn->export->dropConstraint($constraint['tableName'], $constraint['constraintName'],
|
220 |
$constraint['primary']);
|
221 |
}
|
222 |
}
|
223 |
|
224 |
/**
|
225 |
* processCreatedFks
|
226 |
*
|
227 |
* @param string $foreignKeys
|
228 |
* @return void
|
229 |
*/
|
230 |
public function processCreatedFks($foreignKeys)
|
231 |
{
|
232 |
foreach ($foreignKeys as $fk) {
|
233 |
$conn = $this->getConnection($fk['tableName']);
|
234 |
$conn->export->createForeignKey($fk['tableName'], $fk['definition']);
|
235 |
}
|
236 |
}
|
237 |
|
238 |
/**
|
239 |
* processDroppedFks
|
240 |
*
|
241 |
* @param string $foreignKeys
|
242 |
* @return void
|
243 |
*/
|
244 |
public function processDroppedFks($foreignKeys)
|
245 |
{
|
246 |
foreach ($foreignKeys as $fk) {
|
247 |
$conn = $this->getConnection($fk['tableName']);
|
248 |
$conn->export->dropForeignKey($fk['tableName'], $fk['fkName']);
|
249 |
}
|
250 |
}
|
251 |
} |