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
bfa1e77b
Commit
bfa1e77b
authored
Jul 17, 2013
by
Bart Visscher
Committed by
Benjamin Eberlei
Dec 20, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add primary key to 'ALTER TABLE' in MySql
This is at least needed when adding a autoincrement column
parent
01760a4a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+6
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+23
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
bfa1e77b
...
...
@@ -556,6 +556,12 @@ class MySqlPlatform extends AbstractPlatform
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$columnArray
);
}
if
(
isset
(
$diff
->
addedIndexes
[
'primary'
]))
{
$keyColumns
=
array_unique
(
array_values
(
$diff
->
addedIndexes
[
'primary'
]
->
getColumns
()));
$queryParts
[]
=
'ADD PRIMARY KEY ('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
unset
(
$diff
->
addedIndexes
[
'primary'
]);
}
$sql
=
array
();
$tableSql
=
array
();
...
...
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
bfa1e77b
...
...
@@ -320,4 +320,27 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
/**
* @group DBAL-586
*/
public
function
testAddAutoIncrementPrimaryKey
()
{
$keyTable
=
new
Table
(
"foo"
);
$keyTable
->
addColumn
(
"id"
,
"integer"
,
array
(
'autoincrement'
=>
true
));
$keyTable
->
addColumn
(
"baz"
,
"string"
);
$keyTable
->
setPrimaryKey
(
array
(
"id"
));
$oldTable
=
new
Table
(
"foo"
);
$oldTable
->
addColumn
(
"baz"
,
"string"
);
$c
=
new
\Doctrine\DBAL\Schema\Comparator
;
$diff
=
$c
->
diffTable
(
$oldTable
,
$keyTable
);
$sql
=
$this
->
_platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
"ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)"
,
),
$sql
);
}
}
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