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
8b28a9a1
Commit
8b28a9a1
authored
Nov 27, 2013
by
Guilherme Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #435 from deeky666/DBAL-400
[DBAL-400] Fix adding primary key during table alteration in MySQL
parents
4b74a50f
09101dd2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
7 deletions
+60
-7
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+8
-5
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+29
-2
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+23
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
8b28a9a1
...
@@ -602,13 +602,16 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -602,13 +602,16 @@ class MySqlPlatform extends AbstractPlatform
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
$type
=
''
;
$indexClause
=
'INDEX '
.
$addIndex
->
getName
();
if
(
$addIndex
->
isUnique
())
{
$type
=
'UNIQUE '
;
if
(
$addIndex
->
isPrimary
())
{
$indexClause
=
'PRIMARY KEY'
;
}
elseif
(
$addIndex
->
isUnique
())
{
$indexClause
=
'UNIQUE INDEX '
.
$addIndex
->
getName
();
}
}
$query
=
'ALTER TABLE '
.
$table
.
' DROP INDEX '
.
$remIndex
->
getName
()
.
', '
;
$query
=
'ALTER TABLE '
.
$table
.
' DROP INDEX '
.
$remIndex
->
getName
()
.
', '
;
$query
.=
'ADD '
.
$
type
.
'INDEX '
.
$addIndex
->
getName
()
;
$query
.=
'ADD '
.
$
indexClause
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$addIndex
->
getQuotedColumns
(
$this
))
.
')'
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$addIndex
->
getQuotedColumns
(
$this
))
.
')'
;
$sql
[]
=
$query
;
$sql
[]
=
$query
;
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
8b28a9a1
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Schema
;
...
@@ -21,7 +22,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -21,7 +22,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableNew
=
clone
$tableFetched
;
$tableNew
=
clone
$tableFetched
;
$tableNew
->
setPrimaryKey
(
array
(
'bar_id'
,
'foo_id'
));
$tableNew
->
setPrimaryKey
(
array
(
'bar_id'
,
'foo_id'
));
$comparator
=
new
\Doctrine\DBAL\Schema\
Comparator
;
$comparator
=
new
Comparator
;
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$tableFetched
,
$tableNew
));
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$tableFetched
,
$tableNew
));
}
}
...
@@ -42,7 +43,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -42,7 +43,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
_sm
->
createTable
(
$table
);
$this
->
_sm
->
createTable
(
$table
);
$tableFetched
=
$this
->
_sm
->
listTableDetails
(
"diffbug_routing_translations"
);
$tableFetched
=
$this
->
_sm
->
listTableDetails
(
"diffbug_routing_translations"
);
$comparator
=
new
\Doctrine\DBAL\Schema\
Comparator
;
$comparator
=
new
Comparator
;
$diff
=
$comparator
->
diffTable
(
$tableFetched
,
$table
);
$diff
=
$comparator
->
diffTable
(
$tableFetched
,
$table
);
$this
->
assertFalse
(
$diff
,
"no changes expected."
);
$this
->
assertFalse
(
$diff
,
"no changes expected."
);
...
@@ -64,4 +65,30 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -64,4 +65,30 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertArrayHasKey
(
'f_index'
,
$indexes
);
$this
->
assertArrayHasKey
(
'f_index'
,
$indexes
);
$this
->
assertTrue
(
$indexes
[
'f_index'
]
->
hasFlag
(
'fulltext'
));
$this
->
assertTrue
(
$indexes
[
'f_index'
]
->
hasFlag
(
'fulltext'
));
}
}
/**
* @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'
);
$this
->
_sm
->
createTable
(
$table
);
$comparator
=
new
Comparator
();
$diffTable
=
clone
$table
;
$diffTable
->
dropIndex
(
'idx_id'
);
$diffTable
->
setPrimaryKey
(
array
(
'id'
));
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
$table
=
$this
->
_sm
->
listTableDetails
(
"alter_table_add_pk"
);
$this
->
assertFalse
(
$table
->
hasIndex
(
'idx_id'
));
$this
->
assertTrue
(
$table
->
hasPrimaryKey
());
}
}
}
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
8b28a9a1
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\TableDiff
;
...
@@ -295,4 +296,26 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
...
@@ -295,4 +296,26 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'LONGBLOB'
,
$this
->
_platform
->
getBlobTypeDeclarationSQL
(
array
(
'length'
=>
16777216
)));
$this
->
assertEquals
(
'LONGBLOB'
,
$this
->
_platform
->
getBlobTypeDeclarationSQL
(
array
(
'length'
=>
16777216
)));
$this
->
assertEquals
(
'LONGBLOB'
,
$this
->
_platform
->
getBlobTypeDeclarationSQL
(
array
()));
$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
(
'ALTER TABLE alter_table_add_pk DROP INDEX idx_id, ADD PRIMARY KEY (id)'
),
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
))
);
}
}
}
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