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
d1929749
Commit
d1929749
authored
Jan 19, 2016
by
Steve Müller
Committed by
Marco Pivetta
Sep 09, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix another primary key alteration with autoincrement column case on MySQL
fixes #2302
parent
dcce6f86
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
16 deletions
+66
-16
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+39
-16
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+27
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
d1929749
...
@@ -626,24 +626,13 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -626,24 +626,13 @@ class MySqlPlatform extends AbstractPlatform
$sql
=
array
();
$sql
=
array
();
$table
=
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
);
$table
=
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
);
foreach
(
$diff
->
removedIndexes
as
$remKey
=>
$remIndex
)
{
foreach
(
$diff
->
changedIndexes
as
$changedIndex
)
{
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
$sql
=
array_merge
(
$sql
,
$this
->
getPreAlterTableAlterPrimaryKeySQL
(
$diff
,
$changedIndex
));
if
(
$remIndex
->
isPrimary
()
&&
$diff
->
fromTable
instanceof
Table
)
{
foreach
(
$remIndex
->
getColumns
()
as
$columnName
)
{
$column
=
$diff
->
fromTable
->
getColumn
(
$columnName
);
if
(
$column
->
getAutoincrement
()
===
true
)
{
$column
->
setAutoincrement
(
false
);
$sql
[]
=
'ALTER TABLE '
.
$table
.
' MODIFY '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
// original autoincrement information might be needed later on by other parts of the table alteration
$column
->
setAutoincrement
(
true
);
}
}
}
}
foreach
(
$diff
->
removedIndexes
as
$remKey
=>
$remIndex
)
{
$sql
=
array_merge
(
$sql
,
$this
->
getPreAlterTableAlterPrimaryKeySQL
(
$diff
,
$remIndex
));
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
...
@@ -692,6 +681,40 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -692,6 +681,40 @@ class MySqlPlatform extends AbstractPlatform
return
$sql
;
return
$sql
;
}
}
/**
* @param TableDiff $diff
* @param Index $index
*
* @return string[]
*/
private
function
getPreAlterTableAlterPrimaryKeySQL
(
TableDiff
$diff
,
Index
$index
)
{
$sql
=
array
();
if
(
!
$index
->
isPrimary
()
||
!
$diff
->
fromTable
instanceof
Table
)
{
return
$sql
;
}
$tableName
=
$diff
->
getName
(
$this
)
->
getQuotedName
(
$this
);
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach
(
$index
->
getColumns
()
as
$columnName
)
{
$column
=
$diff
->
fromTable
->
getColumn
(
$columnName
);
if
(
$column
->
getAutoincrement
()
===
true
)
{
$column
->
setAutoincrement
(
false
);
$sql
[]
=
'ALTER TABLE '
.
$tableName
.
' MODIFY '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
// original autoincrement information might be needed later on by other parts of the table alteration
$column
->
setAutoincrement
(
true
);
}
}
return
$sql
;
}
/**
/**
* @param TableDiff $diff The table diff to gather the SQL for.
* @param TableDiff $diff The table diff to gather the SQL for.
*
*
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
d1929749
...
@@ -384,6 +384,33 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
...
@@ -384,6 +384,33 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
);
);
}
}
/**
* @group DBAL-2302
*/
public
function
testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn
()
{
$table
=
new
Table
(
"tbl"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'autoincrement'
=>
true
));
$table
->
addColumn
(
'foo'
,
'integer'
);
$table
->
addColumn
(
'bar'
,
'integer'
);
$table
->
setPrimaryKey
(
array
(
'id'
,
'foo'
));
$comparator
=
new
Comparator
();
$diffTable
=
clone
$table
;
$diffTable
->
dropPrimaryKey
();
$diffTable
->
setPrimaryKey
(
array
(
'id'
));
$this
->
assertSame
(
array
(
'ALTER TABLE tbl MODIFY id INT NOT NULL'
,
'ALTER TABLE tbl DROP PRIMARY KEY'
,
'ALTER TABLE tbl ADD PRIMARY KEY (id)'
,
),
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
/**
/**
* @group DBAL-586
* @group DBAL-586
*/
*/
...
...
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