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
8fcc21bf
Commit
8fcc21bf
authored
Dec 20, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-586' into 2.4
parents
01760a4a
aedfbf26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+6
-0
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+58
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
8fcc21bf
...
...
@@ -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 @
8fcc21bf
...
...
@@ -296,6 +296,28 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'LONGBLOB'
,
$this
->
_platform
->
getBlobTypeDeclarationSQL
(
array
()));
}
/**
* @group DBAL-400
*/
public
function
testAlterTableAddPrimaryKey
()
{
$table
=
new
Table
(
'alter_table_add_pk'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'foo'
,
'integer'
);
$table
->
addIndex
(
array
(
'id'
),
'idx_id'
);
$comparator
=
new
Comparator
();
$diffTable
=
clone
$table
;
$diffTable
->
dropIndex
(
'idx_id'
);
$diffTable
->
setPrimaryKey
(
array
(
'id'
));
$this
->
assertEquals
(
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
))
);
}
/**
* @group DBAL-464
*/
...
...
@@ -320,4 +342,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