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
4db178c2
Commit
4db178c2
authored
Apr 06, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-105] Fix rename column detection that went frenzy when changing several columns at once.
parent
0a994387
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+5
-2
ComparatorTest.php
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+28
-0
No files found.
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
4db178c2
...
...
@@ -163,6 +163,7 @@ class Comparator
$changes
++
;
}
}
foreach
(
$table1Columns
as
$columnName
=>
$column
)
{
if
(
$table2
->
hasColumn
(
$columnName
)
)
{
$changedProperties
=
$this
->
diffColumn
(
$column
,
$table2
->
getColumn
(
$columnName
)
);
...
...
@@ -249,7 +250,7 @@ class Comparator
foreach
(
$tableDifferences
->
addedColumns
AS
$addedColumnName
=>
$addedColumn
)
{
foreach
(
$tableDifferences
->
removedColumns
AS
$removedColumnName
=>
$removedColumn
)
{
if
(
count
(
$this
->
diffColumn
(
$addedColumn
,
$removedColumn
))
==
0
)
{
$renameCandidates
[
$addedColumn
->
getName
()][]
=
array
(
$removedColumn
,
$addedColumn
);
$renameCandidates
[
$addedColumn
->
getName
()][]
=
array
(
$removedColumn
,
$addedColumn
,
$addedColumnName
);
}
}
}
...
...
@@ -257,8 +258,10 @@ class Comparator
foreach
(
$renameCandidates
AS
$candidate
=>
$candidateColumns
)
{
if
(
count
(
$candidateColumns
)
==
1
)
{
list
(
$removedColumn
,
$addedColumn
)
=
$candidateColumns
[
0
];
$removedColumnName
=
strtolower
(
$removedColumn
->
getName
());
$addedColumnName
=
strtolower
(
$addedColumn
->
getName
());
$tableDifferences
->
renamedColumns
[
$removedColumn
->
getName
()
]
=
$addedColumn
;
$tableDifferences
->
renamedColumns
[
$removedColumn
Name
]
=
$addedColumn
;
unset
(
$tableDifferences
->
addedColumns
[
$addedColumnName
]);
unset
(
$tableDifferences
->
removedColumns
[
$removedColumnName
]);
}
...
...
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
View file @
4db178c2
...
...
@@ -625,6 +625,34 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertArrayHasKey
(
'id'
,
$tableDiff
->
changedColumns
);
}
/**
* @group DBAL-105
*/
public
function
testDiff
()
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
'twitter_users'
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'autoincrement'
=>
true
));
$table
->
addColumn
(
'twitterId'
,
'integer'
,
array
(
'nullable'
=>
false
));
$table
->
addColumn
(
'displayName'
,
'string'
,
array
(
'nullable'
=>
false
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$newtable
=
new
\Doctrine\DBAL\Schema\Table
(
'twitter_users'
);
$newtable
->
addColumn
(
'id'
,
'integer'
,
array
(
'autoincrement'
=>
true
));
$newtable
->
addColumn
(
'twitter_id'
,
'integer'
,
array
(
'nullable'
=>
false
));
$newtable
->
addColumn
(
'display_name'
,
'string'
,
array
(
'nullable'
=>
false
));
$newtable
->
addColumn
(
'logged_in_at'
,
'datetime'
,
array
(
'nullable'
=>
true
));
$newtable
->
setPrimaryKey
(
array
(
'id'
));
$c
=
new
Comparator
();
$tableDiff
=
$c
->
diffTable
(
$table
,
$newtable
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Schema\TableDiff'
,
$tableDiff
);
$this
->
assertEquals
(
array
(
'twitterid'
,
'displayname'
),
array_keys
(
$tableDiff
->
renamedColumns
));
$this
->
assertEquals
(
array
(
'logged_in_at'
),
array_keys
(
$tableDiff
->
addedColumns
));
$this
->
assertEquals
(
0
,
count
(
$tableDiff
->
removedColumns
));
}
/**
* @param SchemaDiff $diff
* @param int $newTableCount
...
...
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