Commit a615e476 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-140' into 2.1.x

parents 7086a81e 0d8bf90f
......@@ -325,7 +325,10 @@ class Comparator
}
if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
if ($column1->getLength() != $column2->getLength()) {
// check if value of length is set at all, default value assumed otherwise.
$length1 = $column1->getLength() ?: 255;
$length2 = $column2->getLength() ?: 255;
if ($length1 != $length2) {
$changedProperties[] = 'length';
}
......
......@@ -2,11 +2,49 @@
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testSwitchPrimaryKeyColumns()
{
$tableOld = new Table("switch_primary_key_columns");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;
$this->_sm->createTable($tableOld);
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
$tableNew = clone $tableFetched;
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
$comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
}
public function testDiffTableBug()
{
$schema = new Schema();
$table = $schema->createTable('diffbug_routing_translations');
$table->addColumn('id', 'integer');
$table->addColumn('route', 'string');
$table->addColumn('locale', 'string');
$table->addColumn('attribute', 'string');
$table->addColumn('localized_value', 'string');
$table->addColumn('original_value', 'string');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('route', 'locale', 'attribute'));
$table->addIndex(array('localized_value')); // this is much more selective than the unique index
$this->_sm->createTable($table);
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations");
$comparator = new \Doctrine\DBAL\Schema\Comparator;
$diff = $comparator->diffTable($tableFetched, $table);
$this->assertFalse($diff, "no changes expected.");
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Schema\Platforms;
require_once __DIR__ . '/../../../TestInit.php';
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type;
class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Comparator
*/
private $comparator;
/**
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $platform;
public function setUp()
{
$this->comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
}
public function testSwitchPrimaryKeyOrder()
{
$tableOld = new Table("test");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;
$tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
$diff = $this->comparator->diffTable($tableOld, $tableNew);
$sql = $this->platform->getAlterTableSQL($diff);
$this->assertEquals(
array(
'ALTER TABLE test DROP PRIMARY KEY',
'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
), $sql
);
}
}
\ 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