Commit b0bccb92 authored by jsor's avatar jsor

Add custom schema options support to columns including change detection in the comparator

parent b175e1c2
...@@ -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
...@@ -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;
} }
......
...@@ -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');
......
...@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment