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.com>.
|
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.com
|
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 |
$conn->export->alterTable($column['tableName'], array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName']))));
|
122 |
}
|
123 |
}
|
124 |
|
125 |
/**
|
126 |
* processChangedColumns
|
127 |
*
|
128 |
* @param string $columns
|
129 |
* @return void
|
130 |
*/
|
131 |
public function processChangedColumns($columns)
|
132 |
{
|
133 |
foreach ($columns as $column) {
|
134 |
$conn = $this->getConnection($column['tableName']);
|
135 |
|
136 |
$options = array();
|
137 |
$options = $column['options'];
|
138 |
$options['type'] = $column['type'];
|
139 |
|
140 |
$conn->export->alterTable($column['tableName'], array('change' => array($column['columnName'] => array('definition' => $options))));
|
141 |
}
|
142 |
}
|
143 |
|
144 |
/**
|
145 |
* processRemovedColumns
|
146 |
*
|
147 |
* @param string $columns
|
148 |
* @return void
|
149 |
*/
|
150 |
public function processRemovedColumns($columns)
|
151 |
{
|
152 |
foreach ($columns as $column) {
|
153 |
$conn = $this->getConnection($column['tableName']);
|
154 |
|
155 |
$conn->export->alterTable($column['tableName'], array('remove' => array($column['columnName'] => array())));
|
156 |
}
|
157 |
}
|
158 |
|
159 |
/**
|
160 |
* processAddexIndexes
|
161 |
*
|
162 |
* @param string $indexes
|
163 |
* @return void
|
164 |
*/
|
165 |
public function processAddedIndexes($indexes)
|
166 |
{
|
167 |
foreach ($indexes as $index) {
|
168 |
$conn = $this->getConnection($index['tableName']);
|
169 |
|
170 |
$conn->export->createIndex($index['tableName'], $index['indexName'], $index['definition']);
|
171 |
}
|
172 |
}
|
173 |
|
174 |
/**
|
175 |
* processRemovedIndexes
|
176 |
*
|
177 |
* @param string $indexes
|
178 |
* @return void
|
179 |
*/
|
180 |
public function processRemovedIndexes($indexes)
|
181 |
{
|
182 |
foreach ($indexes as $index) {
|
183 |
$conn = $this->getConnection($index['tableName']);
|
184 |
|
185 |
$conn->export->dropIndex($index['tableName'], $index['indexName']);
|
186 |
}
|
187 |
}
|
188 |
|
189 |
/**
|
190 |
* processCreatedConstraints
|
191 |
*
|
192 |
* @param string $constraints
|
193 |
* @return void
|
194 |
*/
|
195 |
public function processCreatedConstraints($constraints)
|
196 |
{
|
197 |
foreach ($constraints as $constraint) {
|
198 |
$conn = $this->getConnection($constraint['tableName']);
|
199 |
$conn->export->createConstraint($constraint['tableName'], $constraint['constraintName'],
|
200 |
$constraint['definition']);
|
201 |
}
|
202 |
}
|
203 |
|
204 |
/**
|
205 |
* processDroppedConstraints
|
206 |
*
|
207 |
* @param string $constraints
|
208 |
* @return void
|
209 |
*/
|
210 |
public function processDroppedConstraints($constraints)
|
211 |
{
|
212 |
foreach ($constraints as $constraint) {
|
213 |
$conn = $this->getConnection($constraint['tableName']);
|
214 |
$conn->export->dropConstraint($constraint['tableName'], $constraint['constraintName'],
|
215 |
$constraint['primary']);
|
216 |
}
|
217 |
}
|
218 |
|
219 |
/**
|
220 |
* processCreatedFks
|
221 |
*
|
222 |
* @param string $foreignKeys
|
223 |
* @return void
|
224 |
*/
|
225 |
public function processCreatedFks($foreignKeys)
|
226 |
{
|
227 |
foreach ($foreignKeys as $fk) {
|
228 |
$conn = $this->getConnection($fk['tableName']);
|
229 |
$conn->export->createForeignKey($fk['tableName'], $fk['definition']);
|
230 |
}
|
231 |
}
|
232 |
|
233 |
/**
|
234 |
* processDroppedFks
|
235 |
*
|
236 |
* @param string $foreignKeys
|
237 |
* @return void
|
238 |
*/
|
239 |
public function processDroppedFks($foreignKeys)
|
240 |
{
|
241 |
foreach ($foreignKeys as $fk) {
|
242 |
$conn = $this->getConnection($fk['tableName']);
|
243 |
$conn->export->dropForeignKey($fk['tableName'], $fk['fkName']);
|
244 |
}
|
245 |
}
|
246 |
} |