From 731c9718aa6fd0c75d62f8f2436987a776526d63 Mon Sep 17 00:00:00 2001 From: beberlei Date: Fri, 11 Dec 2009 00:56:47 +0000 Subject: [PATCH] [2.0] DDC-40 - Matching annotations <-> auto sequence expectations. --- .../ORM/Mapping/ClassMetadataFactory.php | 2 +- .../ORM/Functional/SchemaTool/AllTests.php | 2 +- .../SchemaTool/PostgreSqlSchemaToolTest.php | 33 +++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index a1fca89b8..c9ffeda87 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -400,7 +400,7 @@ class ClassMetadataFactory if ( ! $definition) { $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq'; $definition['sequenceName'] = $this->_targetPlatform->fixSchemaElementName($sequenceName); - $definition['allocationSize'] = 20; + $definition['allocationSize'] = 10; $definition['initialValue'] = 1; $class->setSequenceGeneratorDefinition($definition); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php index d9dd82ae3..90826bb24 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php @@ -20,7 +20,7 @@ class AllTests $suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Functional Tools'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\MySqlSchemaToolTest'); - //$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest'); return $suite; } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index a24a6f403..40a84fec2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -15,6 +15,12 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->markTestSkipped('The ' . __CLASS__ .' requires the use of postgresql.'); } } + + public function testPostgresMetadataSequenceIncrementedBy10() + { + $address = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $this->assertEquals(10, $address->sequenceGeneratorDefinition['allocationSize']); + } public function testGetCreateSchemaSql() { @@ -26,18 +32,19 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); - $this->assertEquals(count($sql), 10); + $this->assertEquals(count($sql), 11); $this->assertEquals("CREATE TABLE cms_addresses (id INT NOT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id))", $sql[0]); - $this->assertEquals("CREATE TABLE cms_users_groups (user_id INT DEFAULT NULL, group_id INT DEFAULT NULL, PRIMARY KEY(user_id, group_id))", $sql[1]); - $this->assertEquals("CREATE TABLE cms_users (id INT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL UNIQUE, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))", $sql[2]); - $this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[3]); - $this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[4]); - $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[5]); - $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[6]); - $this->assertEquals("ALTER TABLE cms_phonenumbers ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[7]); - $this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 20 START 1", $sql[8]); - $this->assertEquals("CREATE SEQUENCE cms_users_id_seq INCREMENT BY 20 START 1", $sql[9]); + $this->assertEquals("CREATE TABLE cms_users (id INT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))", $sql[1]); + $this->assertEquals("CREATE UNIQUE INDEX cms_users_username_uniq ON cms_users (username)", $sql[2]); + $this->assertEquals("CREATE TABLE cms_users_groups (user_id INT DEFAULT NULL, group_id INT DEFAULT NULL, PRIMARY KEY(user_id, group_id))", $sql[3]); + $this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[4]); + $this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[5]); + $this->assertEquals("CREATE SEQUENCE cms_users_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[6]); + $this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[7]); + $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[8]); + $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[9]); + $this->assertEquals("ALTER TABLE cms_phonenumbers ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[10]); } public function testGetCreateSchemaSql2() @@ -51,8 +58,8 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(2, count($sql)); - $this->assertEquals("CREATE TABLE decimal_model (id INT NOT NULL, decimal NUMERIC(2, 5) NOT NULL, PRIMARY KEY(id))", $sql[0]); - $this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 20 START 1", $sql[1]); + $this->assertEquals('CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, PRIMARY KEY(id))', $sql[0]); + $this->assertEquals("CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]); } public function testGetCreateSchemaSql3() @@ -66,6 +73,6 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(2, count($sql)); $this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]); - $this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 20 START 1", $sql[1]); + $this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]); } }