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
b0bccb92
Commit
b0bccb92
authored
Dec 13, 2011
by
jsor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom schema options support to columns including change detection in the comparator
parent
b175e1c2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
1 deletion
+92
-1
Column.php
lib/Doctrine/DBAL/Schema/Column.php
+53
-1
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+16
-0
ColumnTest.php
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
+7
-0
ComparatorTest.php
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
+16
-0
No files found.
lib/Doctrine/DBAL/Schema/Column.php
View file @
b0bccb92
...
@@ -93,6 +93,11 @@ class Column extends AbstractAsset
...
@@ -93,6 +93,11 @@ class Column extends AbstractAsset
*/
*/
protected
$_comment
=
null
;
protected
$_comment
=
null
;
/**
* @var array
*/
protected
$_customSchemaOptions
=
array
();
/**
/**
* Create a new Column
* Create a new Column
*
*
...
@@ -340,6 +345,53 @@ class Column extends AbstractAsset
...
@@ -340,6 +345,53 @@ class Column extends AbstractAsset
return
$this
->
_comment
;
return
$this
->
_comment
;
}
}
/**
* @param string $name
* @param mixed $value
* @return Column
*/
public
function
setCustomSchemaOption
(
$name
,
$value
)
{
$this
->
_customSchemaOptions
[
$name
]
=
$value
;
return
$this
;
}
/**
* @param string $name
* @return boolean
*/
public
function
hasCustomSchemaOption
(
$name
)
{
return
isset
(
$this
->
_customSchemaOptions
[
$name
]);
}
/**
* @param string $name
* @return mixed
*/
public
function
getCustomSchemaOption
(
$name
)
{
return
$this
->
_customSchemaOptions
[
$name
];
}
/**
* @param array $customSchemaOptions
* @return Column
*/
public
function
setCustomSchemaOptions
(
array
$customSchemaOptions
)
{
$this
->
_customSchemaOptions
=
$customSchemaOptions
;
return
$this
;
}
/**
* @return array
*/
public
function
getCustomSchemaOptions
()
{
return
$this
->
_customSchemaOptions
;
}
/**
/**
* @param Visitor $visitor
* @param Visitor $visitor
*/
*/
...
@@ -366,6 +418,6 @@ class Column extends AbstractAsset
...
@@ -366,6 +418,6 @@ class Column extends AbstractAsset
'autoincrement'
=>
$this
->
_autoincrement
,
'autoincrement'
=>
$this
->
_autoincrement
,
'columnDefinition'
=>
$this
->
_columnDefinition
,
'columnDefinition'
=>
$this
->
_columnDefinition
,
'comment'
=>
$this
->
_comment
,
'comment'
=>
$this
->
_comment
,
),
$this
->
_platformOptions
);
),
$this
->
_platformOptions
,
$this
->
_customSchemaOptions
);
}
}
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
b0bccb92
...
@@ -355,6 +355,22 @@ class Comparator
...
@@ -355,6 +355,22 @@ class Comparator
$changedProperties
[]
=
'comment'
;
$changedProperties
[]
=
'comment'
;
}
}
$options1
=
$column1
->
getCustomSchemaOptions
();
$options2
=
$column2
->
getCustomSchemaOptions
();
$commonKeys
=
array_keys
(
array_intersect_key
(
$options1
,
$options2
));
foreach
(
$commonKeys
as
$key
)
{
if
(
$options1
[
$key
]
!==
$options2
[
$key
])
{
$changedProperties
[]
=
$key
;
break
;
}
}
$diffKeys
=
array_keys
(
array_diff_key
(
$options1
,
$options2
)
+
array_diff_key
(
$options2
,
$options1
));
$changedProperties
=
array_merge
(
$changedProperties
,
$diffKeys
);
return
$changedProperties
;
return
$changedProperties
;
}
}
...
...
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
View file @
b0bccb92
...
@@ -30,6 +30,11 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
...
@@ -30,6 +30,11 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$this
->
assertTrue
(
$column
->
hasPlatformOption
(
'foo'
));
$this
->
assertTrue
(
$column
->
hasPlatformOption
(
'foo'
));
$this
->
assertEquals
(
'bar'
,
$column
->
getPlatformOption
(
'foo'
));
$this
->
assertEquals
(
'bar'
,
$column
->
getPlatformOption
(
'foo'
));
$this
->
assertFalse
(
$column
->
hasPlatformOption
(
'bar'
));
$this
->
assertFalse
(
$column
->
hasPlatformOption
(
'bar'
));
$this
->
assertEquals
(
array
(
'bar'
=>
'baz'
),
$column
->
getCustomSchemaOptions
());
$this
->
assertTrue
(
$column
->
hasCustomSchemaOption
(
'bar'
));
$this
->
assertEquals
(
'baz'
,
$column
->
getCustomSchemaOption
(
'bar'
));
$this
->
assertFalse
(
$column
->
hasCustomSchemaOption
(
'foo'
));
}
}
public
function
testToArray
()
public
function
testToArray
()
...
@@ -48,6 +53,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
...
@@ -48,6 +53,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'columnDefinition'
=>
null
,
'columnDefinition'
=>
null
,
'comment'
=>
null
,
'comment'
=>
null
,
'foo'
=>
'bar'
,
'foo'
=>
'bar'
,
'bar'
=>
'baz'
);
);
$this
->
assertEquals
(
$expected
,
$this
->
createColumn
()
->
toArray
());
$this
->
assertEquals
(
$expected
,
$this
->
createColumn
()
->
toArray
());
...
@@ -67,6 +73,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
...
@@ -67,6 +73,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'fixed'
=>
true
,
'fixed'
=>
true
,
'default'
=>
'baz'
,
'default'
=>
'baz'
,
'platformOptions'
=>
array
(
'foo'
=>
'bar'
),
'platformOptions'
=>
array
(
'foo'
=>
'bar'
),
'customSchemaOptions'
=>
array
(
'bar'
=>
'baz'
),
);
);
$string
=
Type
::
getType
(
'string'
);
$string
=
Type
::
getType
(
'string'
);
...
...
tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
View file @
b0bccb92
...
@@ -193,6 +193,22 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
...
@@ -193,6 +193,22 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
array
(),
$c
->
diffColumn
(
$column1
,
$column1
));
$this
->
assertEquals
(
array
(),
$c
->
diffColumn
(
$column1
,
$column1
));
}
}
public
function
testCompareChangedColumns_ChangeCustomSchemaOption
()
{
$column1
=
new
Column
(
'charfield1'
,
Type
::
getType
(
'string'
));
$column2
=
new
Column
(
'charfield1'
,
Type
::
getType
(
'string'
));
$column1
->
setCustomSchemaOption
(
'foo'
,
'bar'
);
$column2
->
setCustomSchemaOption
(
'foo'
,
'bar'
);
$column1
->
setCustomSchemaOption
(
'foo1'
,
'bar1'
);
$column2
->
setCustomSchemaOption
(
'foo2'
,
'bar2'
);
$c
=
new
Comparator
();
$this
->
assertEquals
(
array
(
'foo1'
,
'foo2'
),
$c
->
diffColumn
(
$column1
,
$column2
));
$this
->
assertEquals
(
array
(),
$c
->
diffColumn
(
$column1
,
$column1
));
}
public
function
testCompareRemovedIndex
()
public
function
testCompareRemovedIndex
()
{
{
$schema1
=
new
Schema
(
array
(
$schema1
=
new
Schema
(
array
(
...
...
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