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
121332f1
Commit
121332f1
authored
Dec 20, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-400' into 2.4
parents
76af9c69
4dc09995
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
8 deletions
+53
-8
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+23
-4
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+29
-3
MySqlPlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
+1
-1
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
121332f1
...
...
@@ -115,6 +115,22 @@ class MySqlPlatform extends AbstractPlatform
return
'DATEDIFF('
.
$date1
.
', '
.
$date2
.
')'
;
}
/**
* {@inheritDoc}
*/
public
function
getDateAddHourExpression
(
$date
,
$hours
)
{
return
'DATE_ADD('
.
$date
.
', INTERVAL '
.
$hours
.
' HOUR)'
;
}
/**
* {@inheritDoc}
*/
public
function
getDateSubHourExpression
(
$date
,
$hours
)
{
return
'DATE_SUB('
.
$date
.
', INTERVAL '
.
$hours
.
' HOUR)'
;
}
/**
* {@inheritDoc}
*/
...
...
@@ -605,13 +621,16 @@ class MySqlPlatform extends AbstractPlatform
foreach
(
$diff
->
addedIndexes
as
$addKey
=>
$addIndex
)
{
if
(
$remIndex
->
getColumns
()
==
$addIndex
->
getColumns
())
{
$type
=
''
;
if
(
$addIndex
->
isUnique
())
{
$type
=
'UNIQUE '
;
$indexClause
=
'INDEX '
.
$addIndex
->
getName
();
if
(
$addIndex
->
isPrimary
())
{
$indexClause
=
'PRIMARY KEY'
;
}
elseif
(
$addIndex
->
isUnique
())
{
$indexClause
=
'UNIQUE INDEX '
.
$addIndex
->
getName
();
}
$query
=
'ALTER TABLE '
.
$table
.
' DROP INDEX '
.
$remIndex
->
getName
()
.
', '
;
$query
.=
'ADD '
.
$
type
.
'INDEX '
.
$addIndex
->
getName
()
;
$query
.=
'ADD '
.
$
indexClause
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$addIndex
->
getQuotedColumns
(
$this
))
.
')'
;
$sql
[]
=
$query
;
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
121332f1
...
...
@@ -2,9 +2,9 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Comparator
;
class
MySqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
...
...
@@ -20,7 +20,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableNew
=
clone
$tableFetched
;
$tableNew
->
setPrimaryKey
(
array
(
'bar_id'
,
'foo_id'
));
$comparator
=
new
\Doctrine\DBAL\Schema\
Comparator
;
$comparator
=
new
Comparator
;
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$tableFetched
,
$tableNew
));
}
...
...
@@ -41,7 +41,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
_sm
->
createTable
(
$table
);
$tableFetched
=
$this
->
_sm
->
listTableDetails
(
"diffbug_routing_translations"
);
$comparator
=
new
\Doctrine\DBAL\Schema\
Comparator
;
$comparator
=
new
Comparator
;
$diff
=
$comparator
->
diffTable
(
$tableFetched
,
$table
);
$this
->
assertFalse
(
$diff
,
"no changes expected."
);
...
...
@@ -89,4 +89,30 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertFalse
(
$table
->
hasPrimaryKey
());
$this
->
assertFalse
(
$table
->
getColumn
(
'id'
)
->
getAutoincrement
());
}
/**
* @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 @
121332f1
...
...
@@ -3,12 +3,12 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Comparator
;
class
MySqlPlatformTest
extends
AbstractPlatformTestCase
{
...
...
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