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
f884b305
Commit
f884b305
authored
Mar 14, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-237' into 2.2
parents
54f82879
04b425e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
7 deletions
+79
-7
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+58
-0
TableDiff.php
lib/Doctrine/DBAL/Schema/TableDiff.php
+1
-4
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+20
-3
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
f884b305
...
@@ -519,6 +519,64 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -519,6 +519,64 @@ class MySqlPlatform extends AbstractPlatform
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
}
}
/**
* Fix for DROP/CREATE index after foreign key change from OneToOne to ManyToOne
*
* @param TableDiff $diff
* @return array
*/
protected
function
getPreAlterTableIndexForeignKeySQL
(
TableDiff
$diff
)
{
$sql
=
array
();
$table
=
$diff
->
name
;
foreach
(
$diff
->
removedIndexes
AS
$remKey
=>
$remIndex
)
{
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
$columns
=
$addIndex
->
getColumns
();
$type
=
''
;
if
(
$addIndex
->
isUnique
())
{
$type
=
'UNIQUE '
;
}
$query
=
'ALTER TABLE '
.
$table
.
' DROP INDEX '
.
$remIndex
->
getName
()
.
', '
;
$query
.=
'ADD '
.
$type
.
'INDEX '
.
$addIndex
->
getName
();
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$columns
)
.
')'
;
$sql
[]
=
$query
;
unset
(
$diff
->
removedIndexes
[
$remKey
]);
unset
(
$diff
->
addedIndexes
[
$addKey
]);
break
;
}
}
}
$sql
=
array_merge
(
$sql
,
parent
::
getPreAlterTableIndexForeignKeySQL
(
$diff
));
return
$sql
;
}
/**
* @override
*/
protected
function
getCreateIndexSQLFlags
(
Index
$index
)
{
$type
=
''
;
if
(
$index
->
isUnique
())
{
$type
.=
'UNIQUE '
;
}
else
if
(
$index
->
hasFlag
(
'fulltext'
))
{
$type
.=
'FULLTEXT '
;
}
return
$type
;
}
/**
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
* field to be used in statements like CREATE TABLE.
...
...
lib/Doctrine/DBAL/Schema/TableDiff.php
View file @
f884b305
<?php
<?php
/*
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...
@@ -29,7 +27,6 @@ namespace Doctrine\DBAL\Schema;
...
@@ -29,7 +27,6 @@ namespace Doctrine\DBAL\Schema;
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @license http://ez.no/licenses/new_bsd New BSD License
* @since 2.0
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
*/
class
TableDiff
class
TableDiff
...
@@ -136,4 +133,4 @@ class TableDiff
...
@@ -136,4 +133,4 @@ class TableDiff
$this
->
changedIndexes
=
$changedIndexes
;
$this
->
changedIndexes
=
$changedIndexes
;
$this
->
removedIndexes
=
$removedIndexes
;
$this
->
removedIndexes
=
$removedIndexes
;
}
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
View file @
f884b305
...
@@ -5,9 +5,9 @@ namespace Doctrine\Tests\DBAL\Platforms;
...
@@ -5,9 +5,9 @@ namespace Doctrine\Tests\DBAL\Platforms;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
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\Schema
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Index
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
MySqlPlatformTest
extends
AbstractPlatformTestCase
class
MySqlPlatformTest
extends
AbstractPlatformTestCase
{
{
...
@@ -209,4 +209,21 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
...
@@ -209,4 +209,21 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{
{
return
array
(
"CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) ENGINE = InnoDB"
);
return
array
(
"CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) ENGINE = InnoDB"
);
}
}
}
\ No newline at end of file
/**
* @group DBAL-237
*/
public
function
testChangeIndexWithForeignKeys
()
{
$index
=
new
Index
(
"idx"
,
array
(
"col"
),
false
);
$unique
=
new
Index
(
"uniq"
,
array
(
"col"
),
true
);
$diff
=
new
TableDiff
(
"test"
,
array
(),
array
(),
array
(),
array
(
$unique
),
array
(),
array
(
$index
));
$sql
=
$this
->
_platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
"ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"
),
$sql
);
$diff
=
new
TableDiff
(
"test"
,
array
(),
array
(),
array
(),
array
(
$index
),
array
(),
array
(
$unique
));
$sql
=
$this
->
_platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
"ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"
),
$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