Commit 44cc6465 authored by beberlei's avatar beberlei

[2.0] DDC-169 - Savepoint for Refactorings in Schema-Tool - It is now...

[2.0] DDC-169 - Savepoint for Refactorings in Schema-Tool - It is now generating DDL according to the old and the new mechanisms in parallel. Equality of generation has been verified on Sqlite, Mysql, Oracle. If Postgres is also verified, the old code will be removed in favour of the new one completly.
parent bdae89cb
......@@ -73,7 +73,7 @@ class Column extends AbstractAsset
/**
* @var string
*/
protected $_default;
protected $_default = null;
/**
* @var array
......
......@@ -198,13 +198,13 @@ class Schema extends AbstractAsset
* @param string $sequenceName
* @param int $allocationSize
* @param int $initialValue
* @return Schema
* @return Sequence
*/
public function createSequence($sequenceName, $allocationSize=1, $initialValue=1)
{
$seq = new Sequence($sequenceName, $allocationSize, $initialValue);
$this->_addSequence($seq);
return $this;
return $seq;
}
/**
......
......@@ -53,8 +53,8 @@ class Sequence extends AbstractAsset
public function __construct($name, $allocationSize=1, $initialValue=1)
{
$this->_setName($name);
$this->_allocationSize = (is_int($allocationSize))?:1;
$this->_initialValue = (is_int($initialValue))?:1;
$this->_allocationSize = (is_numeric($allocationSize))?$allocationSize:1;
$this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
}
public function getAllocationSize()
......
......@@ -247,21 +247,28 @@ class Table extends AbstractAsset
* @param array $options
* @return Table
*/
public function addForeignKeyConstraint(Table $foreignTable, array $localColumnNames, array $foreignColumnNames, $name=null, array $options=array())
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, $name=null, array $options=array())
{
foreach ($localColumnNames AS $columnName) {
if (!$this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
if ($foreignTable instanceof Table) {
$foreignTableName = $foreignTable->getName();
foreach ($foreignColumnNames AS $columnName) {
if (!$foreignTable->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
}
}
} else {
$foreignTableName = $foreignTable;
}
foreach ($foreignColumnNames AS $columnName) {
if (!$foreignTable->hasColumn($columnName)) {
foreach ($localColumnNames AS $columnName) {
if (!$this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
}
}
$constraint = new ForeignKeyConstraint(
$localColumnNames, $foreignTable->getName(), $foreignColumnNames, $name, $options
$localColumnNames, $foreignTableName, $foreignColumnNames, $name, $options
);
$this->_addConstraint($constraint);
return $this;
......
......@@ -93,36 +93,17 @@ class CreateSchemaSqlCollector implements Visitor
}
}
}
/**
$column = array();
$column['name'] = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
$column['type'] = Type::getType($mapping['type']);
$column['length'] = isset($mapping['length']) ? $mapping['length'] : null;
$column['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true;
$column['unique'] = isset($mapping['unique']) ? $mapping['unique'] : false;
$column['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false;
if(strtolower($column['type']) == 'string' && $column['length'] === null) {
$column['length'] = 255;
}
if (isset($mapping['precision'])) {
$column['precision'] = $mapping['precision'];
}
if (isset($mapping['scale'])) {
$column['scale'] = $mapping['scale'];
*/
$columns = array();
foreach($columns AS $column) {
foreach($table->getColumns() AS $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
$columnData = array();
$columnData['name'] = $column->getName();
$columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->notNull();
$columnData['unique'] = false;
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOptions('version'):false;
$columnData['notnull'] = $column->getNotNull();
$columnData['unique'] = ($column->hasPlatformOption("unique"))?$column->getPlatformOption('unique'):false;
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false;
if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255;
}
......@@ -139,7 +120,7 @@ class CreateSchemaSqlCollector implements Visitor
}
}
$columns[] = $columnData;
$columns[$columnData['name']] = $columnData;
}
$this->_createTableQueries = array_merge($this->_createTableQueries,
......
This diff is collapsed.
......@@ -108,7 +108,11 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
public function testCreateSequence()
{
$schema = new Schema();
$schema->createSequence('a_seq');
$sequence = $schema->createSequence('a_seq', 10, 20);
$this->assertEquals('a_seq', $sequence->getName());
$this->assertEquals(10, $sequence->getAllocationSize());
$this->assertEquals(20, $sequence->getInitialValue());
$this->assertTrue($schema->hasSequence("a_seq"));
$this->assertType('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
......
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