Commit c8b58d97 authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'hotfix/DBAL-423-optimize-non-native-GUID-type-declaration'

Close #465
parents ecc99eee 83bf4642
......@@ -297,7 +297,7 @@ abstract class AbstractPlatform
/**
* Returns the SQL snippet to declare a GUID/UUID field.
*
* By default this maps directly to a VARCHAR and only maps to more
* By default this maps directly to a CHAR(36) and only maps to more
* special datatypes when the underlying databases support this datatype.
*
* @param array $field
......@@ -306,6 +306,9 @@ abstract class AbstractPlatform
*/
public function getGuidTypeDeclarationSQL(array $field)
{
$field['length'] = 36;
$field['fixed'] = true;
return $this->getVarcharTypeDeclarationSQL($field);
}
......
......@@ -399,7 +399,9 @@ class Comparator
$changedProperties[] = 'default';
}
if ($properties1['type'] instanceof Types\StringType || $properties1['type'] instanceof Types\BinaryType) {
if (($properties1['type'] instanceof Types\StringType && ! $properties1['type'] instanceof Types\GuidType) ||
$properties1['type'] instanceof Types\BinaryType
) {
// check if value of length is set at all, default value assumed otherwise.
$length1 = $properties1['length'] ?: 255;
$length2 = $properties2['length'] ?: 255;
......
......@@ -259,4 +259,24 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$platform->getBlobTypeDeclarationSQL($onlineColumns['col_longblob']->toArray())
);
}
/**
* @group DBAL-423
*/
public function testDiffListGuidTableColumn()
{
$offlineTable = new Table('list_guid_table_column');
$offlineTable->addColumn('col_guid', 'guid');
$this->_sm->dropAndCreateTable($offlineTable);
$onlineTable = $this->_sm->listTableDetails('list_guid_table_column');
$comparator = new Comparator();
$this->assertFalse(
$comparator->diffTable($offlineTable, $onlineTable),
"No differences should be detected with the offline vs online schema."
);
}
}
......@@ -596,4 +596,12 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'"
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -946,4 +946,14 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform->quoteStringLiteral($c)
);
}
/**
* @group DBAL-423
*
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->_platform->getGuidTypeDeclarationSQL(array());
}
}
......@@ -664,4 +664,12 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$this->_platform->getCommentOnColumnSQL('mytable', 'id', null)
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -1101,4 +1101,12 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
),
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -463,4 +463,12 @@ class DB2PlatformTest extends AbstractPlatformTestCase
'RENAME INDEX "schema"."foo" TO "bar"',
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -484,4 +484,12 @@ class OraclePlatformTest extends AbstractPlatformTestCase
'ALTER INDEX "schema"."foo" RENAME TO "bar"',
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -855,4 +855,12 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"',
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -552,4 +552,12 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
'when used with schemas.'
);
}
/**
* @group DBAL-423
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
}
}
......@@ -1107,4 +1107,19 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $comparator->compare($fromSchema, $toSchema));
}
public function testCompareGuidColumns()
{
$comparator = new Comparator();
$column1 = new Column('foo', Type::getType('guid'), array('comment' => 'GUID 1'));
$column2 = new Column(
'foo',
Type::getType('guid'),
array('notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.')
);
$this->assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column1, $column2));
$this->assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column2, $column1));
}
}
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