Skip to content

Commit

Permalink
Force comparator to add comment (json -> json_array)
Browse files Browse the repository at this point in the history
I know, this is REALLY nasty but that was the only way I've found to
make it work properly.
  • Loading branch information
lcobucci committed Nov 18, 2017
1 parent e11d799 commit 104793c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ public function diffColumn(Column $column1, Column $column2)
}
}

// This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3
if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) {
array_shift($changedProperties);

$changedProperties[] = 'comment';
}

if ($properties1['default'] != $properties2['default'] ||
// Null values need to be checked additionally as they tell whether to create or drop a default value.
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
Expand Down Expand Up @@ -497,6 +504,21 @@ public function diffColumn(Column $column1, Column $column2)
return array_unique($changedProperties);
}

/**
* TODO: kill with fire on v3.0
*
* @deprecated
*/
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool
{
if ( ! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
return false;
}

return ( ! $one instanceof Types\JsonArrayType && $other instanceof Types\JsonArrayType)
|| ( ! $other instanceof Types\JsonArrayType && $one instanceof Types\JsonArrayType);
}

/**
* Finds the difference between the indexes $index1 and $index2.
*
Expand Down

0 comments on commit 104793c

Please sign in to comment.