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
bd07dced
Commit
bd07dced
authored
Jan 26, 2015
by
andig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix removing autoincrement column from primary key in MySQL
parent
89d4f06f
Changes
2
Hide 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
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+26
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
bd07dced
...
@@ -654,6 +654,24 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -654,6 +654,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
());
}
}
}
}
$engine
=
'INNODB'
;
$engine
=
'INNODB'
;
if
(
$diff
->
fromTable
instanceof
Table
&&
$diff
->
fromTable
->
hasOption
(
'engine'
))
{
if
(
$diff
->
fromTable
instanceof
Table
&&
$diff
->
fromTable
->
hasOption
(
'engine'
))
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
bd07dced
...
@@ -326,6 +326,32 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
...
@@ -326,6 +326,32 @@ abstract class AbstractMySQLPlatformTestCase 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
* @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