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
95522656
Commit
95522656
authored
Oct 17, 2012
by
Martin Hasoň
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added reference to original schema or table in schema difference classes
parent
68764374
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
22 deletions
+92
-22
ColumnDiff.php
lib/Doctrine/DBAL/Schema/ColumnDiff.php
+8
-2
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+3
-0
SchemaDiff.php
lib/Doctrine/DBAL/Schema/SchemaDiff.php
+9
-2
TableDiff.php
lib/Doctrine/DBAL/Schema/TableDiff.php
+9
-2
ComparatorTest.php
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+63
-16
No files found.
lib/Doctrine/DBAL/Schema/ColumnDiff.php
View file @
95522656
...
@@ -24,7 +24,7 @@ namespace Doctrine\DBAL\Schema;
...
@@ -24,7 +24,7 @@ namespace Doctrine\DBAL\Schema;
/**
/**
* Represent the change of a column
* Represent the change of a column
*
*
*
*
* @link www.doctrine-project.org
* @link www.doctrine-project.org
* @since 2.0
* @since 2.0
* @version $Revision$
* @version $Revision$
...
@@ -44,11 +44,17 @@ class ColumnDiff
...
@@ -44,11 +44,17 @@ class ColumnDiff
*/
*/
public
$changedProperties
=
array
();
public
$changedProperties
=
array
();
public
function
__construct
(
$oldColumnName
,
Column
$column
,
array
$changedProperties
=
array
())
/**
* @var Column
*/
public
$fromColumn
;
public
function
__construct
(
$oldColumnName
,
Column
$column
,
array
$changedProperties
=
array
(),
Column
$fromColumn
=
null
)
{
{
$this
->
oldColumnName
=
$oldColumnName
;
$this
->
oldColumnName
=
$oldColumnName
;
$this
->
column
=
$column
;
$this
->
column
=
$column
;
$this
->
changedProperties
=
$changedProperties
;
$this
->
changedProperties
=
$changedProperties
;
$this
->
fromColumn
=
$fromColumn
;
}
}
public
function
hasChanged
(
$propertyName
)
public
function
hasChanged
(
$propertyName
)
...
...
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
95522656
...
@@ -58,6 +58,7 @@ class Comparator
...
@@ -58,6 +58,7 @@ class Comparator
public
function
compare
(
Schema
$fromSchema
,
Schema
$toSchema
)
public
function
compare
(
Schema
$fromSchema
,
Schema
$toSchema
)
{
{
$diff
=
new
SchemaDiff
();
$diff
=
new
SchemaDiff
();
$diff
->
fromSchema
=
$fromSchema
;
$foreignKeysToTable
=
array
();
$foreignKeysToTable
=
array
();
...
@@ -179,6 +180,7 @@ class Comparator
...
@@ -179,6 +180,7 @@ class Comparator
{
{
$changes
=
0
;
$changes
=
0
;
$tableDifferences
=
new
TableDiff
(
$table1
->
getName
());
$tableDifferences
=
new
TableDiff
(
$table1
->
getName
());
$tableDifferences
->
fromTable
=
$table1
;
$table1Columns
=
$table1
->
getColumns
();
$table1Columns
=
$table1
->
getColumns
();
$table2Columns
=
$table2
->
getColumns
();
$table2Columns
=
$table2
->
getColumns
();
...
@@ -203,6 +205,7 @@ class Comparator
...
@@ -203,6 +205,7 @@ class Comparator
$changedProperties
=
$this
->
diffColumn
(
$column
,
$table2
->
getColumn
(
$columnName
)
);
$changedProperties
=
$this
->
diffColumn
(
$column
,
$table2
->
getColumn
(
$columnName
)
);
if
(
count
(
$changedProperties
)
)
{
if
(
count
(
$changedProperties
)
)
{
$columnDiff
=
new
ColumnDiff
(
$column
->
getName
(),
$table2
->
getColumn
(
$columnName
),
$changedProperties
);
$columnDiff
=
new
ColumnDiff
(
$column
->
getName
(),
$table2
->
getColumn
(
$columnName
),
$changedProperties
);
$columnDiff
->
fromColumn
=
$column
;
$tableDifferences
->
changedColumns
[
$column
->
getName
()]
=
$columnDiff
;
$tableDifferences
->
changedColumns
[
$column
->
getName
()]
=
$columnDiff
;
$changes
++
;
$changes
++
;
}
}
...
...
lib/Doctrine/DBAL/Schema/SchemaDiff.php
View file @
95522656
...
@@ -24,7 +24,7 @@ use \Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -24,7 +24,7 @@ use \Doctrine\DBAL\Platforms\AbstractPlatform;
/**
/**
* Schema Diff
* Schema Diff
*
*
*
*
* @link www.doctrine-project.org
* @link www.doctrine-project.org
* @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
...
@@ -34,6 +34,11 @@ use \Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -34,6 +34,11 @@ use \Doctrine\DBAL\Platforms\AbstractPlatform;
*/
*/
class
SchemaDiff
class
SchemaDiff
{
{
/**
* @var Schema
*/
public
$fromSchema
;
/**
/**
* All added tables
* All added tables
*
*
...
@@ -81,12 +86,14 @@ class SchemaDiff
...
@@ -81,12 +86,14 @@ class SchemaDiff
* @param array(string=>Table) $newTables
* @param array(string=>Table) $newTables
* @param array(string=>TableDiff) $changedTables
* @param array(string=>TableDiff) $changedTables
* @param array(string=>bool) $removedTables
* @param array(string=>bool) $removedTables
* @param Schema $fromSchema
*/
*/
public
function
__construct
(
$newTables
=
array
(),
$changedTables
=
array
(),
$removedTables
=
array
())
public
function
__construct
(
$newTables
=
array
(),
$changedTables
=
array
(),
$removedTables
=
array
()
,
Schema
$fromSchema
=
null
)
{
{
$this
->
newTables
=
$newTables
;
$this
->
newTables
=
$newTables
;
$this
->
changedTables
=
$changedTables
;
$this
->
changedTables
=
$changedTables
;
$this
->
removedTables
=
$removedTables
;
$this
->
removedTables
=
$removedTables
;
$this
->
fromSchema
=
$fromSchema
;
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Schema/TableDiff.php
View file @
95522656
...
@@ -22,7 +22,7 @@ namespace Doctrine\DBAL\Schema;
...
@@ -22,7 +22,7 @@ namespace Doctrine\DBAL\Schema;
/**
/**
* Table Diff
* Table Diff
*
*
*
*
* @link www.doctrine-project.org
* @link www.doctrine-project.org
* @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
...
@@ -111,6 +111,11 @@ class TableDiff
...
@@ -111,6 +111,11 @@ class TableDiff
*/
*/
public
$removedForeignKeys
=
array
();
public
$removedForeignKeys
=
array
();
/**
* @var Table
*/
public
$fromTable
;
/**
/**
* Constructs an TableDiff object.
* Constructs an TableDiff object.
*
*
...
@@ -120,10 +125,11 @@ class TableDiff
...
@@ -120,10 +125,11 @@ class TableDiff
* @param array(string=>Index) $addedIndexes
* @param array(string=>Index) $addedIndexes
* @param array(string=>Index) $changedIndexes
* @param array(string=>Index) $changedIndexes
* @param array(string=>bool) $removedIndexes
* @param array(string=>bool) $removedIndexes
* @param Table $fromTable
*/
*/
public
function
__construct
(
$tableName
,
$addedColumns
=
array
(),
public
function
__construct
(
$tableName
,
$addedColumns
=
array
(),
$changedColumns
=
array
(),
$removedColumns
=
array
(),
$addedIndexes
=
array
(),
$changedColumns
=
array
(),
$removedColumns
=
array
(),
$addedIndexes
=
array
(),
$changedIndexes
=
array
(),
$removedIndexes
=
array
())
$changedIndexes
=
array
(),
$removedIndexes
=
array
()
,
Table
$fromTable
=
null
)
{
{
$this
->
name
=
$tableName
;
$this
->
name
=
$tableName
;
$this
->
addedColumns
=
$addedColumns
;
$this
->
addedColumns
=
$addedColumns
;
...
@@ -132,5 +138,6 @@ class TableDiff
...
@@ -132,5 +138,6 @@ class TableDiff
$this
->
addedIndexes
=
$addedIndexes
;
$this
->
addedIndexes
=
$addedIndexes
;
$this
->
changedIndexes
=
$changedIndexes
;
$this
->
changedIndexes
=
$changedIndexes
;
$this
->
removedIndexes
=
$removedIndexes
;
$this
->
removedIndexes
=
$removedIndexes
;
$this
->
fromTable
=
$fromTable
;
}
}
}
}
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
View file @
95522656
...
@@ -29,6 +29,7 @@ use Doctrine\DBAL\Schema\Schema,
...
@@ -29,6 +29,7 @@ use Doctrine\DBAL\Schema\Schema,
Doctrine\DBAL\Schema\Sequence
,
Doctrine\DBAL\Schema\Sequence
,
Doctrine\DBAL\Schema\SchemaDiff
,
Doctrine\DBAL\Schema\SchemaDiff
,
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\ColumnDiff
,
Doctrine\DBAL\Schema\Comparator
,
Doctrine\DBAL\Schema\Comparator
,
Doctrine\DBAL\Types\Type
,
Doctrine\DBAL\Types\Type
,
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
Doctrine\DBAL\Schema\ForeignKeyConstraint
;
...
@@ -61,7 +62,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -61,7 +62,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
);
)
);
$this
->
assertEquals
(
new
SchemaDiff
(),
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$expected
=
new
SchemaDiff
();
$expected
->
fromSchema
=
$schema1
;
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
public
function
testCompareSame2
()
public
function
testCompareSame2
()
...
@@ -82,7 +85,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -82,7 +85,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
)
)
),
),
)
);
)
);
$this
->
assertEquals
(
new
SchemaDiff
(),
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$expected
=
new
SchemaDiff
();
$expected
->
fromSchema
=
$schema1
;
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
public
function
testCompareMissingTable
()
public
function
testCompareMissingTable
()
...
@@ -94,7 +100,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -94,7 +100,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$schema1
=
new
Schema
(
array
(
$table
),
array
(),
$schemaConfig
);
$schema1
=
new
Schema
(
array
(
$table
),
array
(),
$schemaConfig
);
$schema2
=
new
Schema
(
array
(),
array
(),
$schemaConfig
);
$schema2
=
new
Schema
(
array
(),
array
(),
$schemaConfig
);
$expected
=
new
SchemaDiff
(
array
(),
array
(),
array
(
'bugdb'
=>
$table
)
);
$expected
=
new
SchemaDiff
(
array
(),
array
(),
array
(
'bugdb'
=>
$table
)
,
$schema1
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -108,7 +114,8 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -108,7 +114,8 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$schema1
=
new
Schema
(
array
(),
array
(),
$schemaConfig
);
$schema1
=
new
Schema
(
array
(),
array
(),
$schemaConfig
);
$schema2
=
new
Schema
(
array
(
$table
),
array
(),
$schemaConfig
);
$schema2
=
new
Schema
(
array
(
$table
),
array
(),
$schemaConfig
);
$expected
=
new
SchemaDiff
(
array
(
'bugdb'
=>
$table
),
array
(),
array
()
);
$expected
=
new
SchemaDiff
(
array
(
'bugdb'
=>
$table
),
array
(),
array
(),
$schema1
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -151,6 +158,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -151,6 +158,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
)
)
)
)
);
);
$expected
->
fromSchema
=
$schema1
;
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -181,6 +191,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -181,6 +191,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
)
);
);
$expected
->
fromSchema
=
$schema1
;
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -251,6 +264,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -251,6 +264,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
)
);
);
$expected
->
fromSchema
=
$schema1
;
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -295,6 +311,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -295,6 +311,9 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
)
);
);
$expected
->
fromSchema
=
$schema1
;
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
)
);
}
}
...
@@ -346,8 +365,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -346,8 +365,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
)
);
);
$actual
=
Comparator
::
compareSchemas
(
$schema1
,
$schema2
);
$expected
->
fromSchema
=
$schema1
;
$this
->
assertEquals
(
$expected
,
$actual
);
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
));
}
}
public
function
testCompareChangedIndexFieldPositions
()
public
function
testCompareChangedIndexFieldPositions
()
...
@@ -384,8 +405,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -384,8 +405,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
),
),
)
)
);
);
$actual
=
Comparator
::
compareSchemas
(
$schema1
,
$schema2
);
$expected
->
fromSchema
=
$schema1
;
$this
->
assertEquals
(
$expected
,
$actual
);
$expected
->
changedTables
[
'bugdb'
]
->
fromTable
=
$schema1
->
getTable
(
'bugdb'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$schema1
,
$schema2
));
}
}
public
function
testCompareSequences
()
public
function
testCompareSequences
()
...
@@ -717,8 +740,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -717,8 +740,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$newSchema
=
new
Schema
(
array
(),
array
(),
$config
);
$newSchema
=
new
Schema
(
array
(),
array
(),
$config
);
$newSchema
->
createTable
(
'foo.bar'
);
$newSchema
->
createTable
(
'foo.bar'
);
$c
=
new
Comparator
();
$expected
=
new
SchemaDiff
();
$this
->
assertEquals
(
new
SchemaDiff
(),
$c
->
compare
(
$oldSchema
,
$newSchema
));
$expected
->
fromSchema
=
$oldSchema
;
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$oldSchema
,
$newSchema
));
}
}
/**
/**
...
@@ -735,9 +760,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -735,9 +760,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$newSchema
=
new
Schema
();
$newSchema
=
new
Schema
();
$newSchema
->
createTable
(
'bar'
);
$newSchema
->
createTable
(
'bar'
);
$c
=
new
Comparator
();
$expected
=
new
SchemaDiff
();
$diff
=
$c
->
compare
(
$oldSchema
,
$newSchema
);
$expected
->
fromSchema
=
$oldSchema
;
$this
->
assertEquals
(
new
SchemaDiff
(),
$c
->
compare
(
$oldSchema
,
$newSchema
));
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$oldSchema
,
$newSchema
));
}
}
/**
/**
...
@@ -753,10 +779,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -753,10 +779,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$newSchema
=
new
Schema
();
$newSchema
=
new
Schema
();
$newSchema
->
createTable
(
'bar'
);
$newSchema
->
createTable
(
'bar'
);
$
c
=
new
Comparator
();
$
expected
=
new
SchemaDiff
();
$
diff
=
$c
->
compare
(
$oldSchema
,
$newSchema
)
;
$
expected
->
fromSchema
=
$oldSchema
;
$this
->
assertEquals
(
new
SchemaDiff
(),
$c
->
compare
(
$oldSchema
,
$newSchema
));
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$oldSchema
,
$newSchema
));
}
}
/**
/**
...
@@ -810,6 +836,27 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -810,6 +836,27 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertCount
(
1
,
$diff
->
orphanedForeignKeys
);
$this
->
assertCount
(
1
,
$diff
->
orphanedForeignKeys
);
}
}
public
function
testCompareChangedColumn
()
{
$oldSchema
=
new
Schema
();
$tableFoo
=
$oldSchema
->
createTable
(
'foo'
);
$tableFoo
->
addColumn
(
'id'
,
'integer'
);
$newSchema
=
new
Schema
();
$table
=
$newSchema
->
createTable
(
'foo'
);
$table
->
addColumn
(
'id'
,
'string'
);
$expected
=
new
SchemaDiff
();
$expected
->
fromSchema
=
$oldSchema
;
$tableDiff
=
$expected
->
changedTables
[
'foo'
]
=
new
TableDiff
(
'foo'
);
$tableDiff
->
fromTable
=
$tableFoo
;
$columnDiff
=
$tableDiff
->
changedColumns
[
'id'
]
=
new
ColumnDiff
(
'id'
,
$table
->
getColumn
(
'id'
));
$columnDiff
->
fromColumn
=
$tableFoo
->
getColumn
(
'id'
);
$columnDiff
->
changedProperties
=
array
(
'type'
);
$this
->
assertEquals
(
$expected
,
Comparator
::
compareSchemas
(
$oldSchema
,
$newSchema
));
}
/**
/**
* @param SchemaDiff $diff
* @param SchemaDiff $diff
...
...
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