introduced dropForeignKey() to Export and Migration
This commit is contained in:
parent
9679e5531b
commit
f1c6657c0f
5 changed files with 49 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue