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
2713eaf2
Commit
2713eaf2
authored
Jul 31, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-140 - Bugfix in schema comparison
parent
3c310535
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
3 deletions
+94
-3
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+4
-1
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+40
-2
MySQLSchemaTest.php
.../Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php
+50
-0
No files found.
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
2713eaf2
...
@@ -325,7 +325,10 @@ class Comparator
...
@@ -325,7 +325,10 @@ class Comparator
}
}
if
(
$column1
->
getType
()
instanceof
\Doctrine\DBAL\Types\StringType
)
{
if
(
$column1
->
getType
()
instanceof
\Doctrine\DBAL\Types\StringType
)
{
if
(
$column1
->
getLength
()
!=
$column2
->
getLength
())
{
// check if value of length is set at all, default value assumed otherwise.
$length1
=
$column1
->
getLength
()
?:
255
;
$length2
=
$column2
->
getLength
()
?:
255
;
if
(
$length1
!=
$length2
)
{
$changedProperties
[]
=
'length'
;
$changedProperties
[]
=
'length'
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
2713eaf2
...
@@ -2,11 +2,49 @@
...
@@ -2,11 +2,49 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Schema
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
MySqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
class
MySqlSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
{
{
public
function
testSwitchPrimaryKeyColumns
()
{
$tableOld
=
new
Table
(
"switch_primary_key_columns"
);
$tableOld
->
addColumn
(
'foo_id'
,
'integer'
);
$tableOld
->
addColumn
(
'bar_id'
,
'integer'
);
$tableNew
=
clone
$tableOld
;
$this
->
_sm
->
createTable
(
$tableOld
);
$tableFetched
=
$this
->
_sm
->
listTableDetails
(
"switch_primary_key_columns"
);
$tableNew
=
clone
$tableFetched
;
$tableNew
->
setPrimaryKey
(
array
(
'bar_id'
,
'foo_id'
));
$comparator
=
new
\Doctrine\DBAL\Schema\Comparator
;
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$tableFetched
,
$tableNew
));
}
public
function
testDiffTableBug
()
{
$schema
=
new
Schema
();
$table
=
$schema
->
createTable
(
'diffbug_routing_translations'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'route'
,
'string'
);
$table
->
addColumn
(
'locale'
,
'string'
);
$table
->
addColumn
(
'attribute'
,
'string'
);
$table
->
addColumn
(
'localized_value'
,
'string'
);
$table
->
addColumn
(
'original_value'
,
'string'
);
$table
->
setPrimaryKey
(
array
(
'id'
));
$table
->
addUniqueIndex
(
array
(
'route'
,
'locale'
,
'attribute'
));
$table
->
addIndex
(
array
(
'localized_value'
));
// this is much more selective than the unique index
$this
->
_sm
->
createTable
(
$table
);
$tableFetched
=
$this
->
_sm
->
listTableDetails
(
"diffbug_routing_translations"
);
$comparator
=
new
\Doctrine\DBAL\Schema\Comparator
;
$diff
=
$comparator
->
diffTable
(
$tableFetched
,
$table
);
$this
->
assertFalse
(
$diff
,
"no changes expected."
);
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php
0 → 100644
View file @
2713eaf2
<?php
namespace
Doctrine\Tests\DBAL\Schema\Platforms
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Types\Type
;
class
MySQLSchemaTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Comparator
*/
private
$comparator
;
/**
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private
$platform
;
public
function
setUp
()
{
$this
->
comparator
=
new
\Doctrine\DBAL\Schema\Comparator
;
$this
->
platform
=
new
\Doctrine\DBAL\Platforms\MySqlPlatform
;
}
public
function
testSwitchPrimaryKeyOrder
()
{
$tableOld
=
new
Table
(
"test"
);
$tableOld
->
addColumn
(
'foo_id'
,
'integer'
);
$tableOld
->
addColumn
(
'bar_id'
,
'integer'
);
$tableNew
=
clone
$tableOld
;
$tableOld
->
setPrimaryKey
(
array
(
'foo_id'
,
'bar_id'
));
$tableNew
->
setPrimaryKey
(
array
(
'bar_id'
,
'foo_id'
));
$diff
=
$this
->
comparator
->
diffTable
(
$tableOld
,
$tableNew
);
$sql
=
$this
->
platform
->
getAlterTableSQL
(
$diff
);
$this
->
assertEquals
(
array
(
'ALTER TABLE test DROP PRIMARY KEY'
,
'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
),
$sql
);
}
}
\ No newline at end of file
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