2007-09-19 00:15:17 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id: Process.php 1080 2007-02-10 18:17:08Z jwage $
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
2007-10-21 10:23:59 +04:00
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
/**
|
|
|
|
* Doctrine_Migration_Process
|
|
|
|
*
|
|
|
|
* @package Doctrine
|
2007-10-04 01:43:22 +04:00
|
|
|
* @subpackage Migration
|
2007-09-19 00:15:17 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision: 1080 $
|
2007-10-04 01:43:22 +04:00
|
|
|
* @author Jonathan H. Wage <jwage@mac.com>
|
2007-09-19 00:15:17 +04:00
|
|
|
*/
|
|
|
|
class Doctrine_Migration_Process
|
|
|
|
{
|
2007-10-21 10:23:59 +04:00
|
|
|
/**
|
|
|
|
* getConnection
|
|
|
|
*
|
|
|
|
* @param string $tableName
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 20:26:28 +04:00
|
|
|
public function getConnection($tableName)
|
2007-09-19 00:15:17 +04:00
|
|
|
{
|
2007-09-19 20:26:28 +04:00
|
|
|
return Doctrine::getConnectionByTableName($tableName);
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processCreatedTables
|
|
|
|
*
|
|
|
|
* @param string $tables
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 20:26:28 +04:00
|
|
|
public function processCreatedTables($tables)
|
2007-09-19 23:33:00 +04:00
|
|
|
{
|
2007-09-19 00:15:17 +04:00
|
|
|
foreach ($tables as $table) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($table['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$conn->export->createTable($table['tableName'], $table['fields'], $table['options']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processDroppedTables
|
|
|
|
*
|
|
|
|
* @param string $tables
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processDroppedTables($tables)
|
|
|
|
{
|
|
|
|
foreach ($tables as $table) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($table['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$conn->export->dropTable($table['tableName']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processRenamedTables
|
|
|
|
*
|
|
|
|
* @param string $tables
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processRenamedTables($tables)
|
|
|
|
{
|
|
|
|
foreach ($tables as $table) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($table['newTableName']);
|
|
|
|
|
2007-10-16 03:16:54 +04:00
|
|
|
$conn->export->alterTable($table['oldTableName'], array('name' => $table['newTableName']));
|
2007-09-19 00:15:17 +04:00
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processAddedColumns
|
|
|
|
*
|
|
|
|
* @param string $columns
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processAddedColumns($columns)
|
|
|
|
{
|
|
|
|
foreach ($columns as $column) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($column['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$options = array();
|
|
|
|
$options = $column['options'];
|
|
|
|
$options['type'] = $column['type'];
|
|
|
|
|
2007-10-16 03:16:54 +04:00
|
|
|
$conn->export->alterTable($column['tableName'], array('add' => array($column['columnName'] => $options)));
|
2007-09-19 00:15:17 +04:00
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processRenamedColumns
|
|
|
|
*
|
|
|
|
* @param string $columns
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processRenamedColumns($columns)
|
|
|
|
{
|
|
|
|
foreach ($columns as $column) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($column['tableName']);
|
|
|
|
|
2007-10-16 03:16:54 +04:00
|
|
|
$conn->export->alterTable($column['tableName'], array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName']))));
|
2007-09-19 00:15:17 +04:00
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processChangedColumns
|
|
|
|
*
|
|
|
|
* @param string $columns
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processChangedColumns($columns)
|
|
|
|
{
|
|
|
|
foreach ($columns as $column) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($column['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$options = array();
|
|
|
|
$options = $column['options'];
|
|
|
|
$options['type'] = $column['type'];
|
|
|
|
|
2007-10-16 03:16:54 +04:00
|
|
|
$conn->export->alterTable($column['tableName'], array('change' => array($column['columnName'] => array('definition' => $options))));
|
2007-09-19 00:15:17 +04:00
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processRemovedColumns
|
|
|
|
*
|
|
|
|
* @param string $columns
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processRemovedColumns($columns)
|
|
|
|
{
|
|
|
|
foreach ($columns as $column) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($column['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$conn->export->alterTable($column['tableName'], array('remove' => array($column['columnName'] => array())));
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processAddexIndexes
|
|
|
|
*
|
|
|
|
* @param string $indexes
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processAddedIndexes($indexes)
|
|
|
|
{
|
|
|
|
foreach ($indexes as $index) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($index['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$conn->export->createIndex($index['tableName'], $index['indexName'], $index['definition']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processRemovedIndexes
|
|
|
|
*
|
|
|
|
* @param string $indexes
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-09-19 00:15:17 +04:00
|
|
|
public function processRemovedIndexes($indexes)
|
|
|
|
{
|
|
|
|
foreach ($indexes as $index) {
|
2007-09-19 20:26:28 +04:00
|
|
|
$conn = $this->getConnection($index['tableName']);
|
|
|
|
|
2007-09-19 00:15:17 +04:00
|
|
|
$conn->export->dropIndex($index['tableName'], $index['indexName']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processCreatedConstraints
|
|
|
|
*
|
|
|
|
* @param string $constraints
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-10-16 20:22:02 +04:00
|
|
|
public function processCreatedConstraints($constraints)
|
|
|
|
{
|
|
|
|
foreach ($constraints as $constraint) {
|
|
|
|
$conn = $this->getConnection($constraint['tableName']);
|
|
|
|
$conn->export->createConstraint($constraint['tableName'], $constraint['constraintName'],
|
|
|
|
$constraint['definition']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processDroppedConstraints
|
|
|
|
*
|
|
|
|
* @param string $constraints
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-10-16 20:22:02 +04:00
|
|
|
public function processDroppedConstraints($constraints)
|
|
|
|
{
|
|
|
|
foreach ($constraints as $constraint) {
|
|
|
|
$conn = $this->getConnection($constraint['tableName']);
|
|
|
|
$conn->export->dropConstraint($constraint['tableName'], $constraint['constraintName'],
|
|
|
|
$constraint['primary']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processCreatedFks
|
|
|
|
*
|
|
|
|
* @param string $foreignKeys
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-10-16 21:05:52 +04:00
|
|
|
public function processCreatedFks($foreignKeys)
|
|
|
|
{
|
|
|
|
foreach ($foreignKeys as $fk) {
|
|
|
|
$conn = $this->getConnection($fk['tableName']);
|
|
|
|
$conn->export->createForeignKey($fk['tableName'], $fk['definition']);
|
|
|
|
}
|
|
|
|
}
|
2007-10-21 10:23:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* processDroppedFks
|
|
|
|
*
|
|
|
|
* @param string $foreignKeys
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-10-19 14:58:49 +04:00
|
|
|
public function processDroppedFks($foreignKeys)
|
|
|
|
{
|
|
|
|
foreach ($foreignKeys as $fk) {
|
|
|
|
$conn = $this->getConnection($fk['tableName']);
|
|
|
|
$conn->export->dropForeignKey($fk['tableName'], $fk['fkName']);
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 00:15:17 +04:00
|
|
|
}
|