1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Fixed SchemaTool which was failing to dropSchema due to foreignKeyContraint checks. Fixes DDC-1126

This commit is contained in:
Guilherme Blanco 2011-04-26 12:32:04 -03:00
parent 26bd3e3811
commit fe66d8bc04

View File

@ -598,7 +598,11 @@ class SchemaTool
*/ */
public function getDropSchemaSQL(array $classes) public function getDropSchemaSQL(array $classes)
{ {
$sm = $this->_em->getConnection()->getSchemaManager(); /* @var $conn \Doctrine\DBAL\Connection */
$conn = $this->_em->getConnection();
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$sm = $conn->getSchemaManager();
$sql = array(); $sql = array();
$orderedTables = array(); $orderedTables = array();
@ -633,13 +637,18 @@ class SchemaTool
} }
} }
$supportsForeignKeyConstraints = $conn->getDatabasePlatform()->supportsForeignKeyConstraints();
$dropTablesSql = array(); $dropTablesSql = array();
foreach ($orderedTables AS $tableName) { foreach ($orderedTables AS $tableName) {
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ if ($supportsForeignKeyConstraints) {
$foreignKeys = $sm->listTableForeignKeys($tableName); $foreignKeys = $sm->listTableForeignKeys($tableName);
foreach ($foreignKeys AS $foreignKey) { foreach ($foreignKeys AS $foreignKey) {
$sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName);
} }
}
$dropTablesSql[] = $this->_platform->getDropTableSQL($tableName); $dropTablesSql[] = $this->_platform->getDropTableSQL($tableName);
} }