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
2c1f6d71
Commit
2c1f6d71
authored
Dec 20, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-586'
parents
99180ebf
894493b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+6
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+37
-1
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
2c1f6d71
...
...
@@ -572,6 +572,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 @
2c1f6d71
...
...
@@ -314,7 +314,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$diffTable
->
setPrimaryKey
(
array
(
'id'
));
$this
->
assertEquals
(
array
(
'
ALTER TABLE alter_table_add_pk DROP INDEX idx_id,
ADD PRIMARY KEY (id)'
),
array
(
'
DROP INDEX idx_id ON alter_table_add_pk'
,
'ALTER TABLE alter_table_add_pk
ADD PRIMARY KEY (id)'
),
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
...
...
@@ -343,4 +343,40 @@ 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
);
}
public
function
testNamedPrimaryKey
()
{
$diff
=
new
TableDiff
(
'mytable'
);
$diff
->
changedIndexes
[
'foo_index'
]
=
new
Index
(
'foo_index'
,
array
(
'foo'
),
true
,
true
);
$sql
=
$this
->
_platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
"ALTER TABLE mytable DROP PRIMARY KEY"
,
"ALTER TABLE mytable ADD PRIMARY KEY (foo)"
,
),
$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