Skip to content

Commit

Permalink
Fix text column length change
Browse files Browse the repository at this point in the history
  • Loading branch information
cbotsikas committed Jun 9, 2018
1 parent b9fec6b commit 6486884
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ public function diffColumn(Column $column1, Column $column2)
if ($properties1['fixed'] != $properties2['fixed']) {
$changedProperties[] = 'fixed';
}
} elseif ($properties1['type'] instanceof Types\TextType) {
// check if values of length match. There is no default value for all adapters.
if ($properties1['length'] !== $properties2['length']) {
$changedProperties[] = 'length';
}
} elseif ($properties1['type'] instanceof Types\DecimalType) {
if (($properties1['precision'] ?: 10) != ($properties2['precision'] ?: 10)) {
$changedProperties[] = 'precision';
Expand Down
22 changes: 22 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,28 @@ public function testCompareChangedBinaryColumn()
self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
}

public function testCompareChangedTextColumn()
{
$oldSchema = new Schema();

$tableFoo = $oldSchema->createTable('foo');
$tableFoo->addColumn('id', 'text');

$newSchema = new Schema();
$table = $newSchema->createTable('foo');
$table->addColumn('id', 'text', array('length' => 16777215 + 1));

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
$tableDiff->fromTable = $tableFoo;
$columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id'));
$columnDiff->fromColumn = $tableFoo->getColumn('id');
$columnDiff->changedProperties = array('length');

self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
}

/**
* @group DBAL-617
*/
Expand Down

0 comments on commit 6486884

Please sign in to comment.