Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DDC-1172 - Handle sequence dropping in SchemaTool.

  • Loading branch information...
commit 42c5382a037c95960744341030313c7472f6c15b 1 parent ec748b2
@beberlei beberlei authored
View
18 lib/Doctrine/ORM/Tools/SchemaTool.php
@@ -619,6 +619,24 @@ public function getDropSchemaSQL(array $classes)
}
}
}
+
+ if ($this->_platform->supportsSequences()) {
+ foreach ($schema->getSequences() AS $sequence) {
+ $visitor->acceptSequence($sequence);
+ }
+ foreach ($schema->getTables() AS $table) {
+ /* @var $sequence Table */
+ if ($table->hasPrimaryKey()) {
+ $columns = $table->getPrimaryKey()->getColumns();
+ if (count($columns) == 1) {
+ $checkSequence = $table->getName() . "_" . $columns[0] . "_seq";
+ if ($fullSchema->hasSequence($checkSequence)) {
+ $visitor->acceptSequence($fullSchema->getSequence($checkSequence));
+ }
+ }
+ }
+ }
+ }
return $visitor->getQueries();
}
View
21 tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php
@@ -80,4 +80,25 @@ public function testGetCreateSchemaSql3()
$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 1 MINVALUE 1 START 1", $sql[1]);
}
+
+ public function testGetDropSchemaSql()
+ {
+ $classes = array(
+ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'),
+ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
+ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
+ );
+
+ $tool = new SchemaTool($this->_em);
+ $sql = $tool->getDropSchemaSQL($classes);
+
+ $this->assertEquals(13, count($sql));
+ $dropSequenceSQLs = 0;
+ foreach ($sql AS $stmt) {
+ if (strpos($stmt, "DROP SEQUENCE") === 0) {
+ $dropSequenceSQLs++;
+ }
+ }
+ $this->assertEquals(4, $dropSequenceSQLs, "Expect 4 sequences to be dropped.");
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.