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
932fc184
Commit
932fc184
authored
Jan 19, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-204 - Refactored towards search-path and database/schema handling in comparator code.
parent
2a9e9943
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
205 additions
and
14 deletions
+205
-14
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+1
-1
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+6
-0
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+7
-6
Schema.php
lib/Doctrine/DBAL/Schema/Schema.php
+72
-0
SchemaConfig.php
lib/Doctrine/DBAL/Schema/SchemaConfig.php
+24
-4
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+22
-1
ComparatorTest.php
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+58
-1
TableTest.php
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
+15
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
932fc184
...
@@ -2239,7 +2239,7 @@ abstract class AbstractPlatform
...
@@ -2239,7 +2239,7 @@ abstract class AbstractPlatform
return
Connection
::
TRANSACTION_READ_COMMITTED
;
return
Connection
::
TRANSACTION_READ_COMMITTED
;
}
}
/* supports*() metods */
/* supports*() met
h
ods */
/**
/**
* Whether the platform supports sequences.
* Whether the platform supports sequences.
...
...
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
932fc184
...
@@ -816,10 +816,16 @@ abstract class AbstractSchemaManager
...
@@ -816,10 +816,16 @@ abstract class AbstractSchemaManager
{
{
$schemaConfig
=
new
SchemaConfig
();
$schemaConfig
=
new
SchemaConfig
();
$schemaConfig
->
setMaxIdentifierLength
(
$this
->
_platform
->
getMaxIdentifierLength
());
$schemaConfig
->
setMaxIdentifierLength
(
$this
->
_platform
->
getMaxIdentifierLength
());
$schemaConfig
->
setSearchPaths
(
$this
->
getSchemaSearchPaths
());
return
$schemaConfig
;
return
$schemaConfig
;
}
}
public
function
getSchemaSearchPaths
()
{
return
array
(
$this
->
_conn
->
getDatabase
());
}
/**
/**
* Given a table comment this method tries to extract a typehint for Doctrine Type, or returns
* Given a table comment this method tries to extract a typehint for Doctrine Type, or returns
* the type given as default.
* the type given as default.
...
...
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
932fc184
...
@@ -61,11 +61,11 @@ class Comparator
...
@@ -61,11 +61,11 @@ class Comparator
$foreignKeysToTable
=
array
();
$foreignKeysToTable
=
array
();
foreach
(
$toSchema
->
get
Tables
()
AS
$tableName
=>
$tabl
e
)
{
foreach
(
$toSchema
->
get
FullQualifiedTableNames
()
AS
$tableNam
e
)
{
if
(
!
$fromSchema
->
has
Table
(
$tableName
)
)
{
if
(
!
$fromSchema
->
has
FullQualifiedTable
(
$tableName
)
)
{
$diff
->
newTables
[
$tableName
]
=
$t
able
;
$diff
->
newTables
[
$tableName
]
=
$t
oSchema
->
getFullQualifiedTable
(
$tableName
)
;
}
else
{
}
else
{
$tableDifferences
=
$this
->
diffTable
(
$fromSchema
->
get
Table
(
$tableName
),
$table
);
$tableDifferences
=
$this
->
diffTable
(
$fromSchema
->
get
FullQualifiedTable
(
$tableName
),
$toSchema
->
getFullQualifiedTable
(
$tableName
)
);
if
(
$tableDifferences
!==
false
)
{
if
(
$tableDifferences
!==
false
)
{
$diff
->
changedTables
[
$tableName
]
=
$tableDifferences
;
$diff
->
changedTables
[
$tableName
]
=
$tableDifferences
;
}
}
...
@@ -73,8 +73,9 @@ class Comparator
...
@@ -73,8 +73,9 @@ class Comparator
}
}
/* Check if there are tables removed */
/* Check if there are tables removed */
foreach
(
$fromSchema
->
getTables
()
AS
$tableName
=>
$table
)
{
foreach
(
$fromSchema
->
getFullQualifiedTableNames
()
AS
$tableName
)
{
if
(
!
$toSchema
->
hasTable
(
$tableName
)
)
{
$table
=
$fromSchema
->
getFullQualifiedTable
(
$tableName
);
if
(
!
$toSchema
->
hasFullQualifiedTable
(
$tableName
)
)
{
$diff
->
removedTables
[
$tableName
]
=
$table
;
$diff
->
removedTables
[
$tableName
]
=
$table
;
}
}
...
...
lib/Doctrine/DBAL/Schema/Schema.php
View file @
932fc184
...
@@ -81,6 +81,11 @@ class Schema extends AbstractAsset
...
@@ -81,6 +81,11 @@ class Schema extends AbstractAsset
return
$this
->
_schemaConfig
->
hasExplicitForeignKeyIndexes
();
return
$this
->
_schemaConfig
->
hasExplicitForeignKeyIndexes
();
}
}
public
function
getName
()
{
return
$this
->
_schemaConfig
->
getName
();
}
/**
/**
* @param Table $table
* @param Table $table
*/
*/
...
@@ -143,6 +148,73 @@ class Schema extends AbstractAsset
...
@@ -143,6 +148,73 @@ class Schema extends AbstractAsset
return
isset
(
$this
->
_tables
[
$tableName
]);
return
isset
(
$this
->
_tables
[
$tableName
]);
}
}
/**
* Get all table names, prefixed with a schema name, even the default one
* if present.
*
* @return array
*/
public
function
getFullQualifiedTableNames
()
{
$names
=
array
();
foreach
(
$this
->
_tables
as
$table
)
{
$names
[]
=
$table
->
getFullQualifiedTableName
(
$this
->
_schemaConfig
->
getName
());
}
return
$names
;
}
/**
* Does this schema have a table with the given FQN?
*
* @return bool
*/
public
function
hasFullQualifiedTable
(
$fqTableName
)
{
$fqTableName
=
strtolower
(
$fqTableName
);
if
(
strpos
(
$fqTableName
,
"."
)
===
false
)
{
$shortTableName
=
$fqTableName
;
}
else
{
$parts
=
explode
(
"."
,
$fqTableName
);
$shortTableName
=
$fqTableName
[
1
];
}
foreach
(
$this
->
_tables
as
$table
)
{
foreach
(
$this
->
_schemaConfig
->
getSearchPaths
()
as
$searchPathSchema
)
{
if
(
strtolower
(
$table
->
getFullQualifiedTableName
(
$searchPathSchema
))
==
$fqTableName
)
{
return
true
;
}
}
if
(
strtolower
(
$table
->
getName
())
==
$shortTableName
||
strtolower
(
$table
->
getName
())
==
$fqTableName
)
{
return
true
;
}
}
return
false
;
}
public
function
getFullQualifiedTable
(
$fqTableName
)
{
$fqTableName
=
strtolower
(
$fqTableName
);
if
(
strpos
(
$fqTableName
,
"."
)
===
false
)
{
$shortTableName
=
$fqTableName
;
}
else
{
$parts
=
explode
(
"."
,
$fqTableName
);
$shortTableName
=
$fqTableName
[
1
];
}
foreach
(
$this
->
_tables
as
$table
)
{
foreach
(
$this
->
_schemaConfig
->
getSearchPaths
()
as
$searchPathSchema
)
{
if
(
strtolower
(
$table
->
getFullQualifiedTableName
(
$searchPathSchema
))
==
$fqTableName
)
{
return
$table
;
}
}
if
(
strtolower
(
$table
->
getName
())
==
$shortTableName
)
{
return
$table
;
}
}
throw
SchemaException
::
tableDoesNotExist
(
$fqTableName
);
}
/**
/**
* @param string $sequenceName
* @param string $sequenceName
* @return bool
* @return bool
...
...
lib/Doctrine/DBAL/Schema/SchemaConfig.php
View file @
932fc184
<?php
<?php
/*
/*
* $Id: Schema.php 6876 2009-12-06 23:11:35Z beberlei $
*
* 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
...
@@ -27,7 +25,6 @@ namespace Doctrine\DBAL\Schema;
...
@@ -27,7 +25,6 @@ namespace Doctrine\DBAL\Schema;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @link www.doctrine-project.org
* @since 2.0
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
*/
class
SchemaConfig
class
SchemaConfig
...
@@ -42,6 +39,11 @@ class SchemaConfig
...
@@ -42,6 +39,11 @@ class SchemaConfig
*/
*/
protected
$_maxIdentifierLength
=
63
;
protected
$_maxIdentifierLength
=
63
;
/**
* @var array
*/
protected
$_searchPaths
=
array
();
/**
/**
* @return bool
* @return bool
*/
*/
...
@@ -73,4 +75,22 @@ class SchemaConfig
...
@@ -73,4 +75,22 @@ class SchemaConfig
{
{
return
$this
->
_maxIdentifierLength
;
return
$this
->
_maxIdentifierLength
;
}
}
}
\ No newline at end of file
public
function
setSearchPaths
(
$paths
)
{
$this
->
_searchPaths
=
$paths
;
}
public
function
getSearchPaths
()
{
return
$this
->
_searchPaths
;
}
public
function
getName
()
{
if
(
$this
->
_searchPaths
)
{
return
$this
->
_searchPaths
[
0
];
}
return
""
;
}
}
lib/Doctrine/DBAL/Schema/Table.php
View file @
932fc184
...
@@ -596,6 +596,27 @@ class Table extends AbstractAsset
...
@@ -596,6 +596,27 @@ class Table extends AbstractAsset
return
$this
->
_options
;
return
$this
->
_options
;
}
}
/**
* Get the Fully-Qualified Table Name.
*
* The full-qualified table name is "schema.name". If the table name
* already has a schema, then the schema passed to the method is ignored.
* If no schema is set, then the passed schema is prepended as the table is
* in the current default schema.
*
* @param string $schemaName - Current schema this table is in.
* @return string
*/
public
function
getFullQualifiedTableName
(
$schemaName
)
{
if
(
strpos
(
$this
->
_name
,
"."
)
!==
false
)
{
return
$this
->
_name
;
}
else
if
(
$schemaName
)
{
return
$schemaName
.
"."
.
$this
->
_name
;
}
return
$this
->
_name
;
}
/**
/**
* @param Visitor $visitor
* @param Visitor $visitor
*/
*/
...
@@ -632,4 +653,4 @@ class Table extends AbstractAsset
...
@@ -632,4 +653,4 @@ class Table extends AbstractAsset
$this
->
_fkConstraints
[
$k
]
->
setLocalTable
(
$this
);
$this
->
_fkConstraints
[
$k
]
->
setLocalTable
(
$this
);
}
}
}
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
View file @
932fc184
...
@@ -22,6 +22,7 @@ namespace Doctrine\Tests\DBAL\Schema;
...
@@ -22,6 +22,7 @@ namespace Doctrine\Tests\DBAL\Schema;
require_once
__DIR__
.
'/../../TestInit.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
use
Doctrine\DBAL\Schema\Schema
,
use
Doctrine\DBAL\Schema\Schema
,
Doctrine\DBAL\Schema\SchemaConfig
,
Doctrine\DBAL\Schema\Table
,
Doctrine\DBAL\Schema\Table
,
Doctrine\DBAL\Schema\Column
,
Doctrine\DBAL\Schema\Column
,
Doctrine\DBAL\Schema\Index
,
Doctrine\DBAL\Schema\Index
,
...
@@ -702,6 +703,62 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -702,6 +703,62 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
array
(),
$c
->
diffColumn
(
$column
,
$column2
));
$this
->
assertEquals
(
array
(),
$c
->
diffColumn
(
$column
,
$column2
));
}
}
/**
* @group DBAL-204
*/
public
function
testFqnSchemaComparision
()
{
$config
=
new
SchemaConfig
();
$config
->
setSearchPaths
(
array
(
"foo"
));
$oldSchema
=
new
Schema
(
array
(),
array
(),
$config
);
$oldSchema
->
createTable
(
'bar'
);
$newSchema
=
new
Schema
();
$newSchema
->
createTable
(
'foo.bar'
);
$c
=
new
Comparator
();
$this
->
assertEquals
(
new
SchemaDiff
(),
$c
->
compare
(
$oldSchema
,
$newSchema
));
}
/**
* @group DBAL-204
*/
public
function
testFqnSchemaComparisionDifferent
()
{
$config
=
new
SchemaConfig
();
$config
->
setSearchPaths
(
array
(
"foo"
));
$oldSchema
=
new
Schema
(
array
(),
array
(),
$config
);
$oldSchema
->
createTable
(
'bar'
);
$newSchema
=
new
Schema
();
$newSchema
->
createTable
(
'bar.bar'
);
$c
=
new
Comparator
();
$diff
=
$c
->
compare
(
$oldSchema
,
$newSchema
);
$this
->
assertTrue
(
isset
(
$diff
->
newTables
[
"bar.bar"
]));
$this
->
assertTrue
(
isset
(
$diff
->
removedTables
[
"foo.bar"
]));
}
/**
* @group DBAL-204
*/
public
function
testFqnSchemaComparisionNoSchemaSame
()
{
$config
=
new
SchemaConfig
();
$config
->
setSearchPaths
(
array
(
"foo"
));
$oldSchema
=
new
Schema
(
array
(),
array
(),
$config
);
$oldSchema
->
createTable
(
'bar'
);
$newSchema
=
new
Schema
();
$newSchema
->
createTable
(
'bar'
);
$c
=
new
Comparator
();
$diff
=
$c
->
compare
(
$oldSchema
,
$newSchema
);
$this
->
assertEquals
(
new
SchemaDiff
(),
$c
->
compare
(
$oldSchema
,
$newSchema
));
}
/**
/**
* @param SchemaDiff $diff
* @param SchemaDiff $diff
* @param int $newTableCount
* @param int $newTableCount
...
@@ -727,4 +784,4 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -727,4 +784,4 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$changeSequenceCount
,
count
(
$diff
->
changedSequences
),
"Expected number of changed sequences is wrong."
);
$this
->
assertEquals
(
$changeSequenceCount
,
count
(
$diff
->
changedSequences
),
"Expected number of changed sequences is wrong."
);
$this
->
assertEquals
(
$removeSequenceCount
,
count
(
$diff
->
removedSequences
),
"Expected number of removed sequences is wrong."
);
$this
->
assertEquals
(
$removeSequenceCount
,
count
(
$diff
->
removedSequences
),
"Expected number of removed sequences is wrong."
);
}
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
View file @
932fc184
...
@@ -483,4 +483,18 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
...
@@ -483,4 +483,18 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
"test.test"
,
$table
->
getName
());
$this
->
assertEquals
(
"test.test"
,
$table
->
getName
());
$this
->
assertEquals
(
"`test`.`test`"
,
$table
->
getQuotedName
(
new
\Doctrine\DBAL\Platforms\MySqlPlatform
));
$this
->
assertEquals
(
"`test`.`test`"
,
$table
->
getQuotedName
(
new
\Doctrine\DBAL\Platforms\MySqlPlatform
));
}
}
}
\ No newline at end of file
/**
* @group DBAL-204
*/
public
function
testFullQualifiedTableName
()
{
$table
=
new
Table
(
"`test`.`test`"
);
$this
->
assertEquals
(
'test.test'
,
$table
->
getFullQualifiedTableName
(
"test"
));
$this
->
assertEquals
(
'test.test'
,
$table
->
getFullQualifiedTableName
(
"other"
));
$table
=
new
Table
(
"test"
);
$this
->
assertEquals
(
'test.test'
,
$table
->
getFullQualifiedTableName
(
"test"
));
$this
->
assertEquals
(
'other.test'
,
$table
->
getFullQualifiedTableName
(
"other"
));
}
}
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