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
df4071e1
Unverified
Commit
df4071e1
authored
Dec 27, 2018
by
Sergei Morozov
Committed by
GitHub
Dec 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3415 from morozov/issues/3414
Consider column lengths when comparing indices
parents
c23b864c
ac49cb22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
Index.php
lib/Doctrine/DBAL/Schema/Index.php
+18
-0
IndexTest.php
tests/Doctrine/Tests/DBAL/Schema/IndexTest.php
+30
-0
No files found.
lib/Doctrine/DBAL/Schema/Index.php
View file @
df4071e1
...
...
@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Schema;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
InvalidArgumentException
;
use
function
array_filter
;
use
function
array_keys
;
use
function
array_map
;
use
function
array_search
;
...
...
@@ -211,6 +212,10 @@ class Index extends AbstractAsset implements Constraint
return
false
;
}
if
(
!
$this
->
hasSameColumnLengths
(
$other
))
{
return
false
;
}
if
(
!
$this
->
isUnique
()
&&
!
$this
->
isPrimary
())
{
// this is a special case: If the current key is neither primary or unique, any unique or
// primary key will always have the same effect for the index and there cannot be any constraint
...
...
@@ -336,4 +341,17 @@ class Index extends AbstractAsset implements Constraint
return
!
$this
->
hasOption
(
'where'
)
&&
!
$other
->
hasOption
(
'where'
);
}
/**
* Returns whether the index has the same column lengths as the other
*/
private
function
hasSameColumnLengths
(
self
$other
)
:
bool
{
$filter
=
static
function
(
?
int
$length
)
:
bool
{
return
$length
!==
null
;
};
return
array_filter
(
$this
->
options
[
'lengths'
]
??
[],
$filter
)
===
array_filter
(
$other
->
options
[
'lengths'
]
??
[],
$filter
);
}
}
tests/Doctrine/Tests/DBAL/Schema/IndexTest.php
View file @
df4071e1
...
...
@@ -108,6 +108,36 @@ class IndexTest extends TestCase
self
::
assertTrue
(
$another
->
overrules
(
$partial
));
}
/**
* @param string[] $columns
* @param int[]|null[] $lengths1
* @param int[]|null[] $lengths2
*
* @dataProvider indexLengthProvider
*/
public
function
testFulfilledWithLength
(
array
$columns
,
array
$lengths1
,
array
$lengths2
,
bool
$expected
)
:
void
{
$index1
=
new
Index
(
'index1'
,
$columns
,
false
,
false
,
[],
[
'lengths'
=>
$lengths1
]);
$index2
=
new
Index
(
'index2'
,
$columns
,
false
,
false
,
[],
[
'lengths'
=>
$lengths2
]);
self
::
assertSame
(
$expected
,
$index1
->
isFullfilledBy
(
$index2
));
self
::
assertSame
(
$expected
,
$index2
->
isFullfilledBy
(
$index1
));
}
/**
* @return mixed[][]
*/
public
static
function
indexLengthProvider
()
:
iterable
{
return
[
'empty'
=>
[[
'column'
],
[],
[],
true
],
'same'
=>
[[
'column'
],
[
64
],
[
64
],
true
],
'different'
=>
[[
'column'
],
[
32
],
[
64
],
false
],
'sparse-different-positions'
=>
[[
'column1'
,
'column2'
],
[
0
=>
32
],
[
1
=>
32
],
false
],
'sparse-same-positions'
=>
[[
'column1'
,
'column2'
],
[
null
,
32
],
[
1
=>
32
],
true
],
];
}
/**
* @group DBAL-220
*/
...
...
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