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
9395ca33
Commit
9395ca33
authored
Oct 16, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/2.3' into 2.3
parents
9e37731c
219d96a1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
11 deletions
+55
-11
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+5
-0
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+1
-7
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+15
-3
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+4
-1
ComparatorTest.php
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+30
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
9395ca33
...
@@ -407,6 +407,11 @@ class PostgreSqlPlatform extends AbstractPlatform
...
@@ -407,6 +407,11 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$comment
=
$this
->
getColumnComment
(
$column
))
{
if
(
$columnDiff
->
hasChanged
(
'comment'
)
&&
$comment
=
$this
->
getColumnComment
(
$column
))
{
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$comment
);
$commentsSQL
[]
=
$this
->
getCommentOnColumnSQL
(
$diff
->
name
,
$column
->
getName
(),
$comment
);
}
}
if
(
$columnDiff
->
hasChanged
(
'length'
))
{
$query
=
'ALTER '
.
$column
->
getName
()
.
' TYPE '
.
$column
->
getType
()
->
getSqlDeclaration
(
$column
->
toArray
(),
$this
);
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
$query
;
}
}
}
foreach
(
$diff
->
renamedColumns
as
$oldColumnName
=>
$column
)
{
foreach
(
$diff
->
renamedColumns
as
$oldColumnName
=>
$column
)
{
...
...
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
9395ca33
...
@@ -631,13 +631,7 @@ class SQLServerPlatform extends AbstractPlatform
...
@@ -631,13 +631,7 @@ class SQLServerPlatform extends AbstractPlatform
*/
*/
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
)
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
)
{
{
$autoinc
=
''
;
return
(
!
empty
(
$columnDef
[
'autoincrement'
]))
?
' IDENTITY'
:
''
;
if
(
!
empty
(
$columnDef
[
'autoincrement'
]))
{
$autoinc
=
' IDENTITY'
;
}
$unsigned
=
(
isset
(
$columnDef
[
'unsigned'
])
&&
$columnDef
[
'unsigned'
])
?
' UNSIGNED'
:
''
;
return
$unsigned
.
$autoinc
;
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
9395ca33
...
@@ -46,7 +46,7 @@ class Comparator
...
@@ -46,7 +46,7 @@ class Comparator
/**
/**
* Returns a SchemaDiff object containing the differences between the schemas $fromSchema and $toSchema.
* Returns a SchemaDiff object containing the differences between the schemas $fromSchema and $toSchema.
*
*
* The returned diferences are returned in such a way that they contain the
* The returned dif
f
erences are returned in such a way that they contain the
* operations to change the schema stored in $fromSchema to the schema that is
* operations to change the schema stored in $fromSchema to the schema that is
* stored in $toSchema.
* stored in $toSchema.
*
*
...
@@ -95,6 +95,18 @@ class Comparator
...
@@ -95,6 +95,18 @@ class Comparator
foreach
(
$diff
->
removedTables
as
$tableName
=>
$table
)
{
foreach
(
$diff
->
removedTables
as
$tableName
=>
$table
)
{
if
(
isset
(
$foreignKeysToTable
[
$tableName
]))
{
if
(
isset
(
$foreignKeysToTable
[
$tableName
]))
{
$diff
->
orphanedForeignKeys
=
array_merge
(
$diff
->
orphanedForeignKeys
,
$foreignKeysToTable
[
$tableName
]);
$diff
->
orphanedForeignKeys
=
array_merge
(
$diff
->
orphanedForeignKeys
,
$foreignKeysToTable
[
$tableName
]);
// deleting duplicated foreign keys present on both on the orphanedForeignKey
// and the removedForeignKeys from changedTables
foreach
(
$foreignKeysToTable
[
$tableName
]
as
$foreignKey
)
{
// strtolower the table name to make if compatible with getShortestName
$localTableName
=
strtolower
(
$foreignKey
->
getLocalTableName
());
if
(
isset
(
$diff
->
changedTables
[
$localTableName
]))
{
foreach
(
$diff
->
changedTables
[
$localTableName
]
->
removedForeignKeys
as
$key
=>
$removedForeignKey
)
{
unset
(
$diff
->
changedTables
[
$localTableName
]
->
removedForeignKeys
[
$key
]);
}
}
}
}
}
}
}
...
@@ -262,7 +274,7 @@ class Comparator
...
@@ -262,7 +274,7 @@ class Comparator
/**
/**
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
* however ambigu
outies between different possibilit
es should not lead to renaming at all.
* however ambigu
ities between different possibiliti
es should not lead to renaming at all.
*
*
* @param TableDiff $tableDifferences
* @param TableDiff $tableDifferences
*/
*/
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
View file @
9395ca33
...
@@ -27,9 +27,12 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
...
@@ -27,9 +27,12 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$sm
=
$this
->
_conn
->
getSchemaManager
();
$sm
=
$this
->
_conn
->
getSchemaManager
();
$sm
->
createTable
(
$table
);
$sm
->
createTable
(
$table
);
$this
->
_conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
1
));
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
}
}
$this
->
_conn
->
executeUpdate
(
'DELETE FROM master_slave_table'
);
$this
->
_conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
1
));
}
}
public
function
createMasterSlaveConnection
(
$keepSlave
=
false
)
public
function
createMasterSlaveConnection
(
$keepSlave
=
false
)
...
...
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
View file @
9395ca33
...
@@ -781,6 +781,36 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -781,6 +781,36 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertCount
(
0
,
$diff
->
removedSequences
);
$this
->
assertCount
(
0
,
$diff
->
removedSequences
);
}
}
/**
* You can get multiple drops for a FK when a table referenced by a foreign
* key is deleted, as this FK is referenced twice, once on the orphanedForeignKeys
* array because of the dropped table, and once on changedTables array. We
* now check that the key is present once.
*/
public
function
testAvoidMultipleDropForeignKey
()
{
$oldSchema
=
new
Schema
();
$tableForeign
=
$oldSchema
->
createTable
(
'foreign'
);
$tableForeign
->
addColumn
(
'id'
,
'integer'
);
$table
=
$oldSchema
->
createTable
(
'foo'
);
$table
->
addColumn
(
'fk'
,
'integer'
);
$table
->
addForeignKeyConstraint
(
$tableForeign
,
array
(
'fk'
),
array
(
'id'
));
$newSchema
=
new
Schema
();
$table
=
$newSchema
->
createTable
(
'foo'
);
$c
=
new
Comparator
();
$diff
=
$c
->
compare
(
$oldSchema
,
$newSchema
);
$this
->
assertCount
(
0
,
$diff
->
changedTables
[
'foo'
]
->
removedForeignKeys
);
$this
->
assertCount
(
1
,
$diff
->
orphanedForeignKeys
);
}
/**
/**
* @param SchemaDiff $diff
* @param SchemaDiff $diff
* @param int $newTableCount
* @param int $newTableCount
...
...
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