DDC-541 - Schema Table now return Pk, then Fk, then normal columns in that order
This commit is contained in:
parent
987fbee758
commit
427d4eed29
@ -510,7 +510,24 @@ class Table extends AbstractAsset
|
|||||||
*/
|
*/
|
||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return $this->_columns;
|
$columns = $this->_columns;
|
||||||
|
|
||||||
|
$pkCols = array();
|
||||||
|
$fkCols = array();
|
||||||
|
|
||||||
|
if ($this->hasIndex($this->_primaryKeyName)) {
|
||||||
|
$pkCols = $this->getPrimaryKey()->getColumns();
|
||||||
|
}
|
||||||
|
foreach ($this->getForeignKeys() AS $fk) {
|
||||||
|
/* @var $fk ForeignKeyConstraint */
|
||||||
|
$fkCols = array_merge($fkCols, $fk->getColumns());
|
||||||
|
}
|
||||||
|
$colNames = array_unique(array_merge($pkCols, $fkCols, array_keys($columns)));
|
||||||
|
|
||||||
|
uksort($columns, function($a, $b) use($colNames) {
|
||||||
|
return (array_search($a, $colNames) >= array_search($b, $colNames));
|
||||||
|
});
|
||||||
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$tool = new SchemaTool($this->_em);
|
$tool = new SchemaTool($this->_em);
|
||||||
$sql = $tool->getCreateSchemaSql($classes);
|
$sql = $tool->getCreateSchemaSql($classes);
|
||||||
$this->assertEquals(8, count($sql));
|
$this->assertEquals(8, count($sql));
|
||||||
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT 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)) ENGINE = InnoDB", $sql[0]);
|
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||||
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX cms_users_username_uniq (username), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX cms_users_username_uniq (username), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
||||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[2]);
|
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[2]);
|
||||||
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
|
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
|
||||||
|
@ -34,7 +34,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$sql = $tool->getCreateSchemaSql($classes);
|
$sql = $tool->getCreateSchemaSql($classes);
|
||||||
$this->assertEquals(count($sql), 11);
|
$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_addresses (id INT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, PRIMARY KEY(id))", $sql[0]);
|
||||||
$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 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 UNIQUE INDEX cms_users_username_uniq ON cms_users (username)", $sql[2]);
|
||||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", $sql[3]);
|
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", $sql[3]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user