From abde67f73c7bf9abbaa58f7079c08fa17d72b773 Mon Sep 17 00:00:00 2001 From: romanb Date: Tue, 16 Oct 2007 16:22:02 +0000 Subject: [PATCH] added createConstraint()/dropConstraing() support to migrations --- lib/Doctrine/Migration.php | 48 ++++++++++++++++++++++++------ lib/Doctrine/Migration/Process.php | 18 +++++++++++ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 03a0bd38d..f60a579ef 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -33,15 +33,17 @@ */ class Doctrine_Migration { - protected $changes = array('created_tables' => array(), - 'dropped_tables' => array(), - 'renamed_tables' => array(), - 'added_columns' => array(), - 'renamed_columns' => array(), - 'changed_columns' => array(), - 'removed_columns' => array(), - 'added_indexes' => array(), - 'removed_indexes' => array()), + protected $changes = array('created_tables' => array(), + 'dropped_tables' => array(), + 'renamed_tables' => array(), + 'added_columns' => array(), + 'renamed_columns' => array(), + 'changed_columns' => array(), + 'removed_columns' => array(), + 'added_indexes' => array(), + 'removed_indexes' => array(), + 'created_constraints' => array(), + 'dropped_constraints' => array()), $migrationTableName = 'migration_version', $migrationClassesDirectory = array(), $migrationClasses = array(); @@ -394,6 +396,34 @@ class Doctrine_Migration $this->addChange('renamed_tables', $options); } + /** + * createConstraint + * + * @param string $tableName + * @param string $constraintName + * @return void + */ + public function createConstraint($tableName, $constraintName, array $definition) + { + $options = get_defined_vars(); + + $this->addChange('created_constraints', $options); + } + + /** + * createConstraint + * + * @param string $tableName + * @param string $constraintName + * @return void + */ + public function dropConstraint($tableName, $constraintName, $primary) + { + $options = get_defined_vars(); + + $this->addChange('dropped_constraints', $options); + } + /** * addColumn * diff --git a/lib/Doctrine/Migration/Process.php b/lib/Doctrine/Migration/Process.php index 9c36694df..fc8081ec1 100644 --- a/lib/Doctrine/Migration/Process.php +++ b/lib/Doctrine/Migration/Process.php @@ -124,4 +124,22 @@ class Doctrine_Migration_Process $conn->export->dropIndex($index['tableName'], $index['indexName']); } } + + public function processCreatedConstraints($constraints) + { + foreach ($constraints as $constraint) { + $conn = $this->getConnection($constraint['tableName']); + $conn->export->createConstraint($constraint['tableName'], $constraint['constraintName'], + $constraint['definition']); + } + } + + public function processDroppedConstraints($constraints) + { + foreach ($constraints as $constraint) { + $conn = $this->getConnection($constraint['tableName']); + $conn->export->dropConstraint($constraint['tableName'], $constraint['constraintName'], + $constraint['primary']); + } + } } \ No newline at end of file