Commit c12f764c authored by zYne's avatar zYne

tests for index auto-adding

parent 1ad4afaf
...@@ -97,12 +97,33 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -97,12 +97,33 @@ class Doctrine_Export_Mysql extends Doctrine_Export
} }
$queryFields = $this->getFieldDeclarationList($fields); $queryFields = $this->getFieldDeclarationList($fields);
// build indexes for all foreign key fields (needed in MySQL!!)
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) {
$found = true;
}
}
}
if ( ! $found) {
$options['indexes'] = array($local => array('fields' => array($local => array())));
}
}
}
// add all indexes
if (isset($options['indexes']) && ! empty($options['indexes'])) { if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach($options['indexes'] as $index => $definition) { foreach($options['indexes'] as $index => $definition) {
$queryFields .= ', ' . $this->getIndexDeclaration($index, $definition); $queryFields .= ', ' . $this->getIndexDeclaration($index, $definition);
} }
} }
// attach all primary keys
if (isset($options['primary']) && ! empty($options['primary'])) { if (isset($options['primary']) && ! empty($options['primary'])) {
$queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; $queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
} }
...@@ -124,7 +145,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -124,7 +145,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$type = false; $type = false;
if (!empty($options['type'])) { // get the type of the table
if ( ! empty($options['type'])) {
$type = $options['type']; $type = $options['type'];
} else { } else {
$type = $this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE); $type = $this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE);
...@@ -515,7 +537,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -515,7 +537,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$definition['fields'] = array($definition['fields']); $definition['fields'] = array($definition['fields']);
} }
$query = $type . 'INDEX ' . $name; $query = $type . 'INDEX ' . $this->conn->formatter->getIndexName($name);
$query .= ' (' . $this->getIndexFieldDeclarationList($definition['fields']) . ')'; $query .= ' (' . $this->getIndexFieldDeclarationList($definition['fields']) . ')';
......
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