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
5bfd170d
Commit
5bfd170d
authored
Jan 26, 2015
by
andig
Committed by
Steve Müller
Feb 10, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix removing autoincrement column from primary key in MySQL
parent
c9b85682
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+18
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+26
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
5bfd170d
...
...
@@ -643,6 +643,24 @@ class MySqlPlatform extends AbstractPlatform
}
}
// handle columns that are removed from changed indexes
foreach
(
$diff
->
changedIndexes
as
$chgKey
=>
$chgIndex
)
{
// Dropping primary keys requires to unset autoincrement attribute on the particular column first
if
(
$chgIndex
->
isPrimary
()
&&
$diff
->
fromTable
instanceof
Table
)
{
foreach
(
$diff
->
fromTable
->
getIndex
(
$chgIndex
->
getName
())
->
getColumns
()
as
$columnName
)
{
$column
=
$diff
->
fromTable
->
getColumn
(
$columnName
);
if
(
$column
->
getAutoincrement
()
===
true
&&
in_array
(
$columnName
,
$chgIndex
->
getColumns
())
===
false
)
{
$column
->
setAutoincrement
(
false
);
$sql
[]
=
'ALTER TABLE '
.
$table
.
' MODIFY '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
}
}
}
}
$sql
=
array_merge
(
$sql
,
parent
::
getPreAlterTableIndexForeignKeySQL
(
$diff
));
return
$sql
;
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
5bfd170d
...
...
@@ -325,6 +325,32 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
);
}
/**
* @group DBAL-464
*/
public
function
testAlterPrimaryKeyWithAutoincrementColumn
()
{
$table
=
new
Table
(
"drop_primary_key"
);
$table
->
addColumn
(
'id'
,
'integer'
,
array
(
'primary'
=>
true
,
'autoincrement'
=>
true
));
$table
->
addColumn
(
'foo'
,
'integer'
);
$table
->
setPrimaryKey
(
array
(
'id'
));
$comparator
=
new
Comparator
();
$diffTable
=
clone
$table
;
$diffTable
->
dropPrimaryKey
();
$diffTable
->
setPrimaryKey
(
array
(
'foo'
));
$this
->
assertEquals
(
array
(
'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL'
,
'ALTER TABLE drop_primary_key DROP PRIMARY KEY'
,
'ALTER TABLE drop_primary_key ADD PRIMARY KEY (foo)'
),
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
/**
* @group DBAL-464
*/
...
...
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