1
0
mirror of synced 2024-12-12 22:36:02 +03:00

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

This commit is contained in:
beberlei 2009-12-06 18:55:08 +00:00
parent bf0ef0d0a7
commit ba99f53fd5
5 changed files with 103 additions and 3 deletions

View File

@ -794,4 +794,9 @@ class MySqlPlatform extends AbstractPlatform
{
return 'mysql';
}
public function createsExplicitIndexForForeignKeys()
{
return true;
}
}

View File

@ -51,7 +51,7 @@ abstract class AbstractSchemaManager
/**
* Holds instance of the database platform used for this schema manager
*
* @var \Doctrine\DBAL\Platform\AbstractPlatform
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
protected $_platform;
@ -936,6 +936,6 @@ abstract class AbstractSchemaManager
}
$tables = $this->listTables();
return new Schema($tables, $sequences);
return new Schema($tables, $sequences, $this->_platform->createsExplicitIndexForForeignKeys());
}
}

View File

@ -72,6 +72,10 @@ class Comparator
*/
public function compare(Schema $fromSchema, Schema $toSchema)
{
if ($fromSchema->hasExplicitForeignKeyIndexes() && !$toSchema->hasExplicitForeignKeyIndexes()) {
$toSchema->visit(new \Doctrine\DBAL\Schema\Visitor\FixSchema(true));
}
$diff = new SchemaDiff();
$foreignKeysToTable = array();

View File

@ -46,11 +46,16 @@ class Schema extends AbstractAsset
*/
protected $_sequences = array();
/**
* @var bool
*/
protected $_hasExplicitForeignKeyIndexes = false;
/**
* @param array $tables
* @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) {
$this->_addTable($table);
@ -58,6 +63,15 @@ class Schema extends AbstractAsset
foreach ($sequences AS $sequence) {
$this->_addSequence($sequence);
}
$this->_hasExplicitForeignKeyIndexes = $hasExplicitForeignKeyIndexes;
}
/**
* @return bool
*/
public function hasExplicitForeignKeyIndexes()
{
return $this->_hasExplicitForeignKeyIndexes;
}
/**

View File

@ -0,0 +1,77 @@
<?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)
{
}
}