Commit ba99f53f authored by beberlei's avatar beberlei

[2.0] DDC-169 - Fix implicit/explicit index creation differences between platforms

parent bf0ef0d0
...@@ -794,4 +794,9 @@ class MySqlPlatform extends AbstractPlatform ...@@ -794,4 +794,9 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'mysql'; return 'mysql';
} }
public function createsExplicitIndexForForeignKeys()
{
return true;
}
} }
...@@ -51,7 +51,7 @@ abstract class AbstractSchemaManager ...@@ -51,7 +51,7 @@ abstract class AbstractSchemaManager
/** /**
* Holds instance of the database platform used for this schema manager * Holds instance of the database platform used for this schema manager
* *
* @var \Doctrine\DBAL\Platform\AbstractPlatform * @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/ */
protected $_platform; protected $_platform;
...@@ -936,6 +936,6 @@ abstract class AbstractSchemaManager ...@@ -936,6 +936,6 @@ abstract class AbstractSchemaManager
} }
$tables = $this->listTables(); $tables = $this->listTables();
return new Schema($tables, $sequences); return new Schema($tables, $sequences, $this->_platform->createsExplicitIndexForForeignKeys());
} }
} }
\ No newline at end of file
...@@ -72,6 +72,10 @@ class Comparator ...@@ -72,6 +72,10 @@ class Comparator
*/ */
public function compare(Schema $fromSchema, Schema $toSchema) public function compare(Schema $fromSchema, Schema $toSchema)
{ {
if ($fromSchema->hasExplicitForeignKeyIndexes() && !$toSchema->hasExplicitForeignKeyIndexes()) {
$toSchema->visit(new \Doctrine\DBAL\Schema\Visitor\FixSchema(true));
}
$diff = new SchemaDiff(); $diff = new SchemaDiff();
$foreignKeysToTable = array(); $foreignKeysToTable = array();
......
...@@ -46,11 +46,16 @@ class Schema extends AbstractAsset ...@@ -46,11 +46,16 @@ class Schema extends AbstractAsset
*/ */
protected $_sequences = array(); protected $_sequences = array();
/**
* @var bool
*/
protected $_hasExplicitForeignKeyIndexes = false;
/** /**
* @param array $tables * @param array $tables
* @param array $sequences * @param array $sequences
*/ */
public function __construct(array $tables=array(), array $sequences=array()) public function __construct(array $tables=array(), array $sequences=array(), $hasExplicitForeignKeyIndexes=false)
{ {
foreach ($tables AS $table) { foreach ($tables AS $table) {
$this->_addTable($table); $this->_addTable($table);
...@@ -58,6 +63,15 @@ class Schema extends AbstractAsset ...@@ -58,6 +63,15 @@ class Schema extends AbstractAsset
foreach ($sequences AS $sequence) { foreach ($sequences AS $sequence) {
$this->_addSequence($sequence); $this->_addSequence($sequence);
} }
$this->_hasExplicitForeignKeyIndexes = $hasExplicitForeignKeyIndexes;
}
/**
* @return bool
*/
public function hasExplicitForeignKeyIndexes()
{
return $this->_hasExplicitForeignKeyIndexes;
} }
/** /**
......
<?php
namespace Doctrine\DBAL\Schema\Visitor;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Table,
Doctrine\DBAL\Schema\Schema,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\ForeignKeyConstraint,
Doctrine\DBAL\Schema\Constraint,
Doctrine\DBAL\Schema\Sequence,
Doctrine\DBAL\Schema\Index;
class FixSchema implements Visitor
{
/**
* @var bool
*/
private $_addExplicitIndexForForeignKey = null;
public function __construct($addExplicitIndexForForeignKey)
{
$this->_addExplicitIndexForForeignKey = $addExplicitIndexForForeignKey;
}
/**
* @param Schema $schema
*/
public function acceptSchema(Schema $schema)
{
}
/**
* @param Table $table
*/
public function acceptTable(Table $table)
{
}
/**
* @param Column $column
*/
public function acceptColunn(Table $table, Column $column)
{
}
/**
* @param Table $localTable
* @param ForeignKeyConstraint $fkConstraint
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
{
if ($this->_addExplicitIndexForForeignKey) {
$localTable->addIndex($fkConstraint->getColumns());
}
}
/**
* @param Table $table
* @param Index $index
*/
public function acceptIndex(Table $table, Index $index)
{
}
/**
* @param Sequence $sequence
*/
public function acceptSequence(Sequence $sequence)
{
}
}
\ No newline at end of file
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