Commit 8a0898d3 authored by romanb's avatar romanb

Several fixes for mysql export module (incorrectly added indices)

Ticket: 408
parent 7583a8d8
......@@ -101,15 +101,20 @@ class Doctrine_Export_Mysql extends Doctrine_Export
if (isset($options['foreignKeys'])) {
foreach ($options['foreignKeys'] as $fk) {
$local = $fk['local'];
$found = false;
if (isset($options['indexes'])) {
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;
}
}
}
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) {
$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',
'foreign' => 'id',
'foreignTable' => 'sometable')),
'indexes' => array('myindex' => array('fields' => array('foreignKey' => array()))),
'indexes' => array('myindex' => array('fields' => array('foreignKey'))),
);
$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[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('charset', 'utf8');
$this->option('type', 'INNODB');
$this->index('index_category', array('fields' => 'category_id'));
$this->index('index_language', array('fields' => 'language_id'));
$this->index('index_category', array('fields' => array('category_id')));
$this->index('index_language', array('fields' => array('language_id')));
}
}
class Cms_Category extends Doctrine_Record
......@@ -36,6 +36,6 @@ class Cms_Category extends Doctrine_Record
$this->option('collate', 'utf8_unicode_ci');
$this->option('charset', 'utf8');
$this->option('type', 'INNODB');
$this->index('index_parent', array('fields' => 'parent'));
$this->index('index_parent', array('fields' => array('parent')));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment