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
fbed76eb
Commit
fbed76eb
authored
Apr 26, 2017
by
Steve Müller
Committed by
GitHub
Apr 26, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2696 from drieschel/pk_add_column_mysql
MySQL: Fix primary key alteration when adding new columns
parents
23301dc9
fa2a12e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+4
-0
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+24
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
fbed76eb
...
...
@@ -709,6 +709,10 @@ class MySqlPlatform extends AbstractPlatform
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
foreach
(
$index
->
getColumns
()
as
$columnName
)
{
if
(
!
$diff
->
fromTable
->
hasColumn
(
$columnName
))
{
continue
;
}
$column
=
$diff
->
fromTable
->
getColumn
(
$columnName
);
if
(
$column
->
getAutoincrement
()
===
true
)
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
fbed76eb
...
...
@@ -473,6 +473,30 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"ALTER TABLE mytable ADD PRIMARY KEY (foo)"
,
),
$sql
);
}
public
function
testAlterPrimaryKeyWithNewColumn
()
{
$table
=
new
Table
(
"yolo"
);
$table
->
addColumn
(
'pkc1'
,
'integer'
);
$table
->
addColumn
(
'col_a'
,
'integer'
);
$table
->
setPrimaryKey
(
array
(
'pkc1'
));
$comparator
=
new
Comparator
();
$diffTable
=
clone
$table
;
$diffTable
->
addColumn
(
'pkc2'
,
'integer'
);
$diffTable
->
dropPrimaryKey
();
$diffTable
->
setPrimaryKey
(
array
(
'pkc1'
,
'pkc2'
));
$this
->
assertSame
(
array
(
'ALTER TABLE yolo DROP PRIMARY KEY'
,
'ALTER TABLE yolo ADD pkc2 INT NOT NULL'
,
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)'
,
),
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
public
function
testInitializesDoctrineTypeMappings
()
{
...
...
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