From 0f3abde413455e8eb3f9688569fbfb949c18e48e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 21 Jan 2012 11:29:48 +0100 Subject: [PATCH] [DBAL-204] Filter namespaced assets if Schemas/Emulation is not supported. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 8 +++++- lib/vendor/doctrine-dbal | 2 +- .../SchemaTool/MySqlSchemaToolTest.php | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index b0d14eb26..efe7f7b7c 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -21,6 +21,8 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\ORMException, Doctrine\DBAL\Types\Type, + Doctrine\DBAL\Schema\Schema, + Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets, Doctrine\ORM\EntityManager, Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Internal\CommitOrderCalculator, @@ -127,7 +129,7 @@ class SchemaTool $sm = $this->_em->getConnection()->getSchemaManager(); $metadataSchemaConfig = $sm->createSchemaConfig(); $metadataSchemaConfig->setExplicitForeignKeyIndexes(false); - $schema = new \Doctrine\DBAL\Schema\Schema(array(), array(), $metadataSchemaConfig); + $schema = new Schema(array(), array(), $metadataSchemaConfig); $evm = $this->_em->getEventManager(); @@ -252,6 +254,10 @@ class SchemaTool } } + if ( ! $this->_platform->supportsSchemas() && ! $this->_platform->canEmulateSchemas() ) { + $schema->visit(new RemoveNamespacedAssets()); + } + if ($evm->hasListeners(ToolEvents::postGenerateSchema)) { $evm->dispatchEvent(ToolEvents::postGenerateSchema, new GenerateSchemaEventArgs($this->_em, $schema)); } diff --git a/lib/vendor/doctrine-dbal b/lib/vendor/doctrine-dbal index 29b714b7f..480b127fb 160000 --- a/lib/vendor/doctrine-dbal +++ b/lib/vendor/doctrine-dbal @@ -1 +1 @@ -Subproject commit 29b714b7fe72641d749ae90324a5759853fe09b0 +Subproject commit 480b127fb5c35d6fbd70964a228cd63cfe2b7e14 diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index 74d68ca60..5937d8d6e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -64,4 +64,31 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($sql)); $this->assertEquals("CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]); } + + /** + * @group DBAL-204 + */ + public function testGetCreateSchemaSql4() + { + $classes = array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\MysqlSchemaNamespacedEntity') + ); + + $tool = new SchemaTool($this->_em); + $sql = $tool->getCreateSchemaSql($classes); + + $this->assertEquals(0, count($sql)); + } + } + +/** + * @Entity + * @Table("namespace.entity") + */ +class MysqlSchemaNamespacedEntity +{ + /** @Column(type="integer") @Id @GeneratedValue */ + public $id; +} +