Several fixes for mysql export module (incorrectly added indices)
Ticket: 408
This commit is contained in:
parent
7583a8d8ac
commit
8a0898d3ed
@ -101,15 +101,20 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
if (isset($options['foreignKeys'])) {
|
if (isset($options['foreignKeys'])) {
|
||||||
foreach ($options['foreignKeys'] as $fk) {
|
foreach ($options['foreignKeys'] as $fk) {
|
||||||
$local = $fk['local'];
|
$local = $fk['local'];
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
if (isset($options['indexes'])) {
|
if (isset($options['indexes'])) {
|
||||||
foreach ($options['indexes'] as $definition) {
|
foreach ($options['indexes'] as $definition) {
|
||||||
if (isset($definition['fields'][$local]) && count($definition['fields']) === 1) {
|
if (in_array($local, $definition['fields']) && count($definition['fields']) === 1) {
|
||||||
|
// Index already exists on the column
|
||||||
$found = true;
|
$found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isset($options['primary']) && !empty($options['primary']) &&
|
||||||
|
in_array($local, $options['primary'])) {
|
||||||
|
// field is part of the PK and therefore already indexed
|
||||||
|
$found = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! $found) {
|
if ( ! $found) {
|
||||||
$options['indexes'][$local] = array('fields' => array($local => array()));
|
$options['indexes'][$local] = array('fields' => array($local => array()));
|
||||||
|
@ -200,12 +200,11 @@ class Doctrine_Export_Mysql_TestCase extends Doctrine_UnitTestCase
|
|||||||
'foreignKeys' => array(array('local' => 'foreignKey',
|
'foreignKeys' => array(array('local' => 'foreignKey',
|
||||||
'foreign' => 'id',
|
'foreign' => 'id',
|
||||||
'foreignTable' => 'sometable')),
|
'foreignTable' => 'sometable')),
|
||||||
'indexes' => array('myindex' => array('fields' => array('foreignKey' => array()))),
|
'indexes' => array('myindex' => array('fields' => array('foreignKey'))),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$sql = $this->export->createTableSql($name, $fields, $options);
|
$sql = $this->export->createTableSql($name, $fields, $options);
|
||||||
|
|
||||||
$this->assertEqual($sql[0], 'CREATE TABLE mytable (id TINYINT(1), foreignKey INT, INDEX myindex_idx (foreignKey)) ENGINE = INNODB');
|
$this->assertEqual($sql[0], 'CREATE TABLE mytable (id TINYINT(1), foreignKey INT, INDEX myindex_idx (foreignKey)) ENGINE = INNODB');
|
||||||
$this->assertEqual($sql[1], 'ALTER TABLE mytable ADD CONSTRAINT FOREIGN KEY (foreignKey) REFERENCES sometable(id)');
|
$this->assertEqual($sql[1], 'ALTER TABLE mytable ADD CONSTRAINT FOREIGN KEY (foreignKey) REFERENCES sometable(id)');
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ class Cms_CategoryLanguages extends Doctrine_Record
|
|||||||
$this->option('collate', 'utf8_unicode_ci');
|
$this->option('collate', 'utf8_unicode_ci');
|
||||||
$this->option('charset', 'utf8');
|
$this->option('charset', 'utf8');
|
||||||
$this->option('type', 'INNODB');
|
$this->option('type', 'INNODB');
|
||||||
$this->index('index_category', array('fields' => 'category_id'));
|
$this->index('index_category', array('fields' => array('category_id')));
|
||||||
$this->index('index_language', array('fields' => 'language_id'));
|
$this->index('index_language', array('fields' => array('language_id')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Cms_Category extends Doctrine_Record
|
class Cms_Category extends Doctrine_Record
|
||||||
@ -36,6 +36,6 @@ class Cms_Category extends Doctrine_Record
|
|||||||
$this->option('collate', 'utf8_unicode_ci');
|
$this->option('collate', 'utf8_unicode_ci');
|
||||||
$this->option('charset', 'utf8');
|
$this->option('charset', 'utf8');
|
||||||
$this->option('type', 'INNODB');
|
$this->option('type', 'INNODB');
|
||||||
$this->index('index_parent', array('fields' => 'parent'));
|
$this->index('index_parent', array('fields' => array('parent')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user