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
4067c725
Commit
4067c725
authored
Jan 09, 2015
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hotfix/#769-allow-implicit-indexes-overrides' into 2.5
Backport #769 into 2.5
parents
f7acb858
cd203453
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
2 deletions
+93
-2
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+21
-2
TableTest.php
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
+72
-0
No files found.
lib/Doctrine/DBAL/Schema/Table.php
View file @
4067c725
...
...
@@ -42,6 +42,11 @@ class Table extends AbstractAsset
*/
protected
$_columns
=
array
();
/**
* @var Index[]
*/
private
$implicitIndexes
=
array
();
/**
* @var Index[]
*/
...
...
@@ -491,11 +496,24 @@ class Table extends AbstractAsset
{
$indexName
=
$indexCandidate
->
getName
();
$indexName
=
$this
->
normalizeIdentifier
(
$indexName
);
$replacedImplicitIndexes
=
array
();
if
(
isset
(
$this
->
_indexes
[
$indexName
])
||
(
$this
->
_primaryKeyName
!=
false
&&
$indexCandidate
->
isPrimary
()))
{
foreach
(
$this
->
implicitIndexes
as
$name
=>
$implicitIndex
)
{
if
(
$implicitIndex
->
isFullfilledBy
(
$indexCandidate
)
&&
isset
(
$this
->
_indexes
[
$name
]))
{
$replacedImplicitIndexes
[]
=
$name
;
}
}
if
((
isset
(
$this
->
_indexes
[
$indexName
])
&&
!
in_array
(
$indexName
,
$replacedImplicitIndexes
,
true
))
||
(
$this
->
_primaryKeyName
!=
false
&&
$indexCandidate
->
isPrimary
())
)
{
throw
SchemaException
::
indexAlreadyExists
(
$indexName
,
$this
->
_name
);
}
foreach
(
$replacedImplicitIndexes
as
$name
)
{
unset
(
$this
->
_indexes
[
$name
],
$this
->
implicitIndexes
[
$name
]);
}
if
(
$indexCandidate
->
isPrimary
())
{
$this
->
_primaryKeyName
=
$indexName
;
}
...
...
@@ -541,7 +559,8 @@ class Table extends AbstractAsset
}
}
$this
->
addIndex
(
$constraint
->
getColumns
());
$this
->
_addIndex
(
$indexCandidate
);
$this
->
implicitIndexes
[
$this
->
normalizeIdentifier
(
$indexName
)]
=
$indexCandidate
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
View file @
4067c725
...
...
@@ -491,6 +491,78 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertTrue
(
$table
->
hasIndex
(
'idx_unique'
));
}
public
function
testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConstraintIndex
()
{
$foreignTable
=
new
Table
(
'foreign'
);
$foreignTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
=
new
Table
(
'local'
);
$localTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
->
addForeignKeyConstraint
(
$foreignTable
,
array
(
'id'
),
array
(
'id'
));
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$localTable
->
addIndex
(
array
(
'id'
),
'explicit_idx'
);
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$this
->
assertTrue
(
$localTable
->
hasIndex
(
'explicit_idx'
));
}
public
function
testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstraintIndex
()
{
$foreignTable
=
new
Table
(
'foreign'
);
$foreignTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
=
new
Table
(
'local'
);
$localTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
->
addForeignKeyConstraint
(
$foreignTable
,
array
(
'id'
),
array
(
'id'
));
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$localTable
->
addUniqueIndex
(
array
(
'id'
),
'explicit_idx'
);
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$this
->
assertTrue
(
$localTable
->
hasIndex
(
'explicit_idx'
));
}
public
function
testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstraintIndex
()
{
$foreignTable
=
new
Table
(
'foreign'
);
$foreignTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
=
new
Table
(
'local'
);
$localTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
->
addForeignKeyConstraint
(
$foreignTable
,
array
(
'id'
),
array
(
'id'
));
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$localTable
->
setPrimaryKey
(
array
(
'id'
),
'explicit_idx'
);
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$this
->
assertTrue
(
$localTable
->
hasIndex
(
'explicit_idx'
));
}
public
function
testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyConstraintIndexWithSameNameDoesNotThrowException
()
{
$foreignTable
=
new
Table
(
'foreign'
);
$foreignTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
=
new
Table
(
'local'
);
$localTable
->
addColumn
(
'id'
,
'integer'
);
$localTable
->
addForeignKeyConstraint
(
$foreignTable
,
array
(
'id'
),
array
(
'id'
));
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$this
->
assertTrue
(
$localTable
->
hasIndex
(
'IDX_8BD688E8BF396750'
));
$implicitIndex
=
$localTable
->
getIndex
(
'IDX_8BD688E8BF396750'
);
$localTable
->
addIndex
(
array
(
'id'
),
'IDX_8BD688E8BF396750'
);
$this
->
assertCount
(
1
,
$localTable
->
getIndexes
());
$this
->
assertTrue
(
$localTable
->
hasIndex
(
'IDX_8BD688E8BF396750'
));
$this
->
assertNotSame
(
$implicitIndex
,
$localTable
->
getIndex
(
'IDX_8BD688E8BF396750'
));
}
/**
* @group DBAL-64
*/
...
...
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