diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index cc7478474..4bcb59396 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -127,9 +127,20 @@ class Doctrine_Export extends Doctrine_Connection_Module public function dropConstraint($table, $name, $primary = false) { $table = $this->conn->quoteIdentifier($table); - $name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name)); + $name = $this->conn->quoteIdentifier($name); return $this->conn->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name); } + /** + * drop existing foreign key + * + * @param string $table name of table that should be used in method + * @param string $name name of the foreign key to be dropped + * @return void + */ + public function dropForeignKey($table, $name) + { + return $this->dropConstraint($table, $name); + } /** * dropSequenceSql * drop existing sequence diff --git a/lib/Doctrine/Export/Mysql.php b/lib/Doctrine/Export/Mysql.php index b3e47906b..86facf549 100644 --- a/lib/Doctrine/Export/Mysql.php +++ b/lib/Doctrine/Export/Mysql.php @@ -636,4 +636,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export $table = $this->conn->quoteIdentifier($table, true); return 'DROP TABLE ' . $table; } + + public function dropForeignKey($table, $name) + { + $table = $this->conn->quoteIdentifier($table); + $name = $this->conn->quoteIdentifier($name); + return $this->conn->exec('ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $name); + } } \ No newline at end of file diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 23aa40409..f8e0d89ee 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -34,17 +34,19 @@ class Doctrine_Migration { protected $changes = array('created_tables' => array(), - 'dropped_tables' => array(), 'renamed_tables' => array(), + 'created_constraints' => array(), + 'dropped_fks' => array(), + 'created_fks' => array(), + 'dropped_constraints' => array(), + 'dropped_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(), - 'created_fks' => array()), + 'removed_indexes' => array() + ), $migrationTableName = 'migration_version', $migrationClassesDirectory = array(), $migrationClasses = array(); @@ -439,6 +441,20 @@ class Doctrine_Migration $this->addChange('created_fks', $options); } + /** + * dropForeignKey + * + * @param string $tableName + * @param string $constraintName + * @return void + */ + public function dropForeignKey($tableName, $fkName) + { + $options = get_defined_vars(); + + $this->addChange('dropped_fks', $options); + } + /** * addColumn * diff --git a/lib/Doctrine/Migration/Process.php b/lib/Doctrine/Migration/Process.php index c0351f268..93549710c 100644 --- a/lib/Doctrine/Migration/Process.php +++ b/lib/Doctrine/Migration/Process.php @@ -150,4 +150,12 @@ class Doctrine_Migration_Process $conn->export->createForeignKey($fk['tableName'], $fk['definition']); } } + + public function processDroppedFks($foreignKeys) + { + foreach ($foreignKeys as $fk) { + $conn = $this->getConnection($fk['tableName']); + $conn->export->dropForeignKey($fk['tableName'], $fk['fkName']); + } + } } \ No newline at end of file diff --git a/tests/ExportTestCase.php b/tests/ExportTestCase.php index 900cc5c17..3ff67fa4c 100644 --- a/tests/ExportTestCase.php +++ b/tests/ExportTestCase.php @@ -56,7 +56,7 @@ class Doctrine_Export_TestCase extends Doctrine_UnitTestCase { $this->export->dropConstraint('sometable', 'relevancy'); - $this->assertEqual($this->adapter->pop(), 'ALTER TABLE sometable DROP CONSTRAINT relevancy_idx'); + $this->assertEqual($this->adapter->pop(), 'ALTER TABLE sometable DROP CONSTRAINT relevancy'); } public function testCreateIndexExecutesSql() {