Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
1595a431
Unverified
Commit
1595a431
authored
Nov 18, 2017
by
Luís Cobucci
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bc-break/fix-json_array-fields' into 2.6
Backporting
https://github.com/doctrine/dbal/pull/2855
parents
0b32c9e7
fc39d071
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
8 deletions
+167
-8
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+22
-0
JsonArrayType.php
lib/Doctrine/DBAL/Types/JsonArrayType.php
+1
-1
JsonType.php
lib/Doctrine/DBAL/Types/JsonType.php
+1
-6
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+1
-1
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+142
-0
No files found.
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
1595a431
...
@@ -435,6 +435,13 @@ class Comparator
...
@@ -435,6 +435,13 @@ class Comparator
}
}
}
}
// 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'
]
||
if
(
$properties1
[
'default'
]
!=
$properties2
[
'default'
]
||
// Null values need to be checked additionally as they tell whether to create or drop a default value.
// 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.
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
...
@@ -497,6 +504,21 @@ class Comparator
...
@@ -497,6 +504,21 @@ class Comparator
return
array_unique
(
$changedProperties
);
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.
* Finds the difference between the indexes $index1 and $index2.
*
*
...
...
lib/Doctrine/DBAL/Types/JsonArrayType.php
View file @
1595a431
...
@@ -57,6 +57,6 @@ class JsonArrayType extends JsonType
...
@@ -57,6 +57,6 @@ class JsonArrayType extends JsonType
*/
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
{
return
!
$platform
->
hasNativeJsonType
()
;
return
true
;
}
}
}
}
lib/Doctrine/DBAL/Types/JsonType.php
View file @
1595a431
...
@@ -90,12 +90,7 @@ class JsonType extends Type
...
@@ -90,12 +90,7 @@ class JsonType extends Type
*/
*/
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
public
function
requiresSQLCommentHint
(
AbstractPlatform
$platform
)
{
{
/*
return
!
$platform
->
hasNativeJsonType
();
* should be switched back to the platform detection at 3.0, when
* JsonArrayType will be dropped
*/
//return ! $platform->hasNativeJsonType();
return
true
;
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
1595a431
...
@@ -383,7 +383,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -383,7 +383,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** @var Schema\Column[] $columns */
/** @var Schema\Column[] $columns */
$columns
=
$this
->
_sm
->
listTableColumns
(
'test_jsonb'
);
$columns
=
$this
->
_sm
->
listTableColumns
(
'test_jsonb'
);
$this
->
assertSame
(
TYPE
::
JSON
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
$this
->
assertSame
(
$type
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
$this
->
assertTrue
(
true
,
$columns
[
'foo'
]
->
getPlatformOption
(
'jsonb'
));
$this
->
assertTrue
(
true
,
$columns
[
'foo'
]
->
getPlatformOption
(
'jsonb'
));
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
1595a431
...
@@ -1165,4 +1165,146 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -1165,4 +1165,146 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
assertArrayHasKey
(
'explicit_fk1_idx'
,
$indexes
);
$this
->
assertArrayHasKey
(
'explicit_fk1_idx'
,
$indexes
);
$this
->
assertArrayHasKey
(
'idx_3d6c147fdc58d6c'
,
$indexes
);
$this
->
assertArrayHasKey
(
'idx_3d6c147fdc58d6c'
,
$indexes
);
}
}
/**
* @after
*/
public
function
removeJsonArrayTable
()
:
void
{
if
(
$this
->
_sm
->
tablesExist
([
'json_array_test'
]))
{
$this
->
_sm
->
dropTable
(
'json_array_test'
);
}
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComment
()
:
void
{
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json_array'
);
$this
->
_sm
->
createTable
(
$table
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_array_test'
),
$table
);
self
::
assertFalse
(
$tableDiff
);
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArrayTypeOnLegacyPlatforms
()
:
void
{
if
(
$this
->
_sm
->
getDatabasePlatform
()
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
'This test is only supported on platforms that do not have native JSON type.'
);
}
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json_array'
);
$this
->
_sm
->
createTable
(
$table
);
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json'
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_array_test'
),
$table
);
self
::
assertInstanceOf
(
TableDiff
::
class
,
$tableDiff
);
$changedColumn
=
$tableDiff
->
changedColumns
[
'parameters'
]
??
$tableDiff
->
changedColumns
[
'PARAMETERS'
];
self
::
assertSame
([
'comment'
],
$changedColumn
->
changedProperties
);
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
'This test is only supported on platforms that have native JSON type.'
);
}
$this
->
_conn
->
executeQuery
(
'CREATE TABLE json_array_test (parameters JSON NOT NULL)'
);
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json_array'
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_array_test'
),
$table
);
self
::
assertInstanceOf
(
TableDiff
::
class
,
$tableDiff
);
self
::
assertSame
([
'comment'
],
$tableDiff
->
changedColumns
[
'parameters'
]
->
changedProperties
);
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
'This test is only supported on platforms that have native JSON type.'
);
}
$this
->
_conn
->
executeQuery
(
'CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'
);
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json_array'
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_array_test'
),
$table
);
self
::
assertInstanceOf
(
TableDiff
::
class
,
$tableDiff
);
self
::
assertSame
([
'notnull'
,
'comment'
],
$tableDiff
->
changedColumns
[
'parameters'
]
->
changedProperties
);
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
'This test is only supported on platforms that have native JSON type.'
);
}
$this
->
_conn
->
executeQuery
(
'CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'
);
$table
=
new
Table
(
'json_array_test'
);
$table
->
addColumn
(
'parameters'
,
'json_array'
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_array_test'
),
$table
);
self
::
assertInstanceOf
(
TableDiff
::
class
,
$tableDiff
);
self
::
assertSame
([
'notnull'
,
'comment'
],
$tableDiff
->
changedColumns
[
'parameters'
]
->
changedProperties
);
}
/**
* @group 2782
* @group 6654
*/
public
function
testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
hasNativeJsonType
())
{
$this
->
markTestSkipped
(
'This test is only supported on platforms that have native JSON type.'
);
}
$this
->
_conn
->
executeQuery
(
'CREATE TABLE json_test (parameters JSON NOT NULL)'
);
$table
=
new
Table
(
'json_test'
);
$table
->
addColumn
(
'parameters'
,
'json'
);
$comparator
=
new
Comparator
();
$tableDiff
=
$comparator
->
diffTable
(
$this
->
_sm
->
listTableDetails
(
'json_test'
),
$table
);
self
::
assertFalse
(
$tableDiff
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment