Commit b016a5e4 authored by beberlei's avatar beberlei

Removed idGeneratorType concept from Schema\Table instances and fixed all the affected code

parent 83db1210
...@@ -700,7 +700,7 @@ abstract class AbstractPlatform ...@@ -700,7 +700,7 @@ abstract class AbstractPlatform
$columnData['type'] = $column->getType(); $columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength(); $columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->getNotNull(); $columnData['notnull'] = $column->getNotNull();
$columnData['unique'] = ($column->hasPlatformOption("unique"))?$column->getPlatformOption('unique'):false; $columnData['unique'] = false; // TODO: what do we do about this?
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false; $columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false;
if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) { if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255; $columnData['length'] = 255;
...@@ -709,13 +709,10 @@ abstract class AbstractPlatform ...@@ -709,13 +709,10 @@ abstract class AbstractPlatform
$columnData['scale'] = $column->getScale(); $columnData['scale'] = $column->getScale();
$columnData['default'] = $column->getDefault(); $columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition(); $columnData['columnDefinition'] = $column->getColumnDefinition();
$columnData['autoincrement'] = $column->getAutoincrement();
if(in_array($column->getName(), $options['primary'])) { if(in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true; $columnData['primary'] = true;
if($table->isIdGeneratorIdentity()) {
$columnData['autoincrement'] = true;
}
} }
$columns[$columnData['name']] = $columnData; $columns[$columnData['name']] = $columnData;
......
...@@ -215,15 +215,7 @@ abstract class AbstractSchemaManager ...@@ -215,15 +215,7 @@ abstract class AbstractSchemaManager
} }
$indexes = $this->listTableIndexes($tableName); $indexes = $this->listTableIndexes($tableName);
$idGeneratorType = Table::ID_NONE; return new Table($tableName, $columns, $indexes, $foreignKeys, false, array());
foreach ($columns AS $column) {
/* @var $column Column */
if ($column->getAutoincrement()) {
$idGeneratorType = Table::ID_IDENTITY;
}
}
return new Table($tableName, $columns, $indexes, $foreignKeys, $idGeneratorType, array());
} }
/** /**
......
...@@ -178,7 +178,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -178,7 +178,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$autoincrement = true; $autoincrement = true;
} }
if ($tableColumn['default'] == 'NULL') { if (stripos($tableColumn['default'], 'NULL') === 0) {
$tableColumn['default'] = null; $tableColumn['default'] = null;
} }
......
...@@ -36,21 +36,6 @@ use Doctrine\DBAL\DBALException; ...@@ -36,21 +36,6 @@ use Doctrine\DBAL\DBALException;
*/ */
class Table extends AbstractAsset class Table extends AbstractAsset
{ {
/**
* @var int
*/
const ID_NONE = 0;
/**
* @var int
*/
const ID_SEQUENCE = 1;
/**
* @var int
*/
const ID_IDENTITY = 2;
/** /**
* @var string * @var string
*/ */
...@@ -81,11 +66,6 @@ class Table extends AbstractAsset ...@@ -81,11 +66,6 @@ class Table extends AbstractAsset
*/ */
protected $_options = array(); protected $_options = array();
/**
* @var bool
*/
protected $_idGeneratorType = self::ID_NONE;
/** /**
* @var SchemaConfig * @var SchemaConfig
*/ */
...@@ -100,7 +80,7 @@ class Table extends AbstractAsset ...@@ -100,7 +80,7 @@ class Table extends AbstractAsset
* @param int $idGeneratorType * @param int $idGeneratorType
* @param array $options * @param array $options
*/ */
public function __construct($tableName, array $columns=array(), array $indexes=array(), array $fkConstraints=array(), $idGeneratorType=self::ID_NONE, array $options=array()) public function __construct($tableName, array $columns=array(), array $indexes=array(), array $fkConstraints=array(), $idGeneratorType = 0, array $options=array())
{ {
if (strlen($tableName) == 0) { if (strlen($tableName) == 0) {
throw DBALException::invalidTableName($tableName); throw DBALException::invalidTableName($tableName);
...@@ -163,16 +143,6 @@ class Table extends AbstractAsset ...@@ -163,16 +143,6 @@ class Table extends AbstractAsset
return $primaryKey; return $primaryKey;
} }
/**
* @param string $type
* @return Table
*/
public function setIdGeneratorType($type)
{
$this->_idGeneratorType = $type;
return $this;
}
/** /**
* @param array $columnNames * @param array $columnNames
* @param string $indexName * @param string $indexName
...@@ -489,22 +459,6 @@ class Table extends AbstractAsset ...@@ -489,22 +459,6 @@ class Table extends AbstractAsset
return $this->_fkConstraints[$constraintName]; return $this->_fkConstraints[$constraintName];
} }
/**
* @return bool
*/
public function isIdGeneratorIdentity()
{
return ($this->_idGeneratorType==self::ID_IDENTITY);
}
/**
* @return array
*/
public function isIdGeneratorSequence()
{
return ($this->_idGeneratorType==self::ID_SEQUENCE);
}
/** /**
* @return Column[] * @return Column[]
*/ */
......
...@@ -367,7 +367,6 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -367,7 +367,6 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$table = new \Doctrine\DBAL\Schema\Table('test_autoincrement'); $table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
$table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY);
$table->addColumn('id', 'integer', array('autoincrement' => true)); $table->addColumn('id', 'integer', array('autoincrement' => true));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
...@@ -394,9 +393,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -394,9 +393,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
protected function getTestTable($name, $options=array()) protected function getTestTable($name, $options=array())
{ {
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), \Doctrine\DBAL\Schema\Table::ID_NONE, $options); $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options);
$table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY);
$table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('id', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$table->addColumn('test', 'string', array('length' => 255)); $table->addColumn('test', 'string', array('length' => 255));
......
...@@ -45,10 +45,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -45,10 +45,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testGeneratesTableCreationSql() public function testGeneratesTableCreationSql()
{ {
$table = new \Doctrine\DBAL\Schema\Table('test'); $table = new \Doctrine\DBAL\Schema\Table('test');
$table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true));
$table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); $table->addColumn('test', 'string', array('notnull' => false, 'length' => 255));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY);
$sql = $this->_platform->getCreateTableSQL($table); $sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getGenerateTableSql(), $sql[0]); $this->assertEquals($this->getGenerateTableSql(), $sql[0]);
......
...@@ -583,13 +583,11 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase ...@@ -583,13 +583,11 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
public function testDetectChangeIdentifierType() public function testDetectChangeIdentifierType()
{ {
$this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.');
$tableA = new Table("foo"); $tableA = new Table("foo");
$tableA->addColumn('id', 'integer', array('platformOptions' => array('autoincrement' => false))); $tableA->addColumn('id', 'integer', array('autoincrement' => false));
$tableB = new Table("foo"); $tableB = new Table("foo");
$tableB->addColumn('id', 'integer', array('platformOptions' => array('autoincrement' => true))); $tableB->addColumn('id', 'integer', array('autoincrement' => true));
$c = new Comparator(); $c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB); $tableDiff = $c->diffTable($tableA, $tableB);
......
...@@ -185,21 +185,6 @@ class TableTest extends \PHPUnit_Framework_TestCase ...@@ -185,21 +185,6 @@ class TableTest extends \PHPUnit_Framework_TestCase
$table = new Table("foo", $columns, $indexes, array()); $table = new Table("foo", $columns, $indexes, array());
} }
public function testIdGenerator()
{
$tableA = new Table("foo", array(), array(), array(), Table::ID_NONE);
$this->assertFalse($tableA->isIdGeneratorIdentity());
$this->assertFalse($tableA->isIdGeneratorSequence());;
$tableB = new Table("foo", array(), array(), array(), Table::ID_IDENTITY);
$this->assertTrue($tableB->isIdGeneratorIdentity());
$this->assertFalse($tableB->isIdGeneratorSequence());;
$tableC = new Table("foo", array(), array(), array(), Table::ID_SEQUENCE);
$this->assertFalse($tableC->isIdGeneratorIdentity());
$this->assertTrue($tableC->isIdGeneratorSequence());;
}
public function testConstraints() public function testConstraints()
{ {
$constraint = new ForeignKeyConstraint(array(), "foo", array()); $constraint = new ForeignKeyConstraint(array(), "foo", array());
...@@ -213,7 +198,7 @@ class TableTest extends \PHPUnit_Framework_TestCase ...@@ -213,7 +198,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testOptions() public function testOptions()
{ {
$table = new Table("foo", array(), array(), array(), Table::ID_NONE, array("foo" => "bar")); $table = new Table("foo", array(), array(), array(), false, array("foo" => "bar"));
$this->assertTrue($table->hasOption("foo")); $this->assertTrue($table->hasOption("foo"));
$this->assertEquals("bar", $table->getOption("foo")); $this->assertEquals("bar", $table->getOption("foo"));
...@@ -281,17 +266,6 @@ class TableTest extends \PHPUnit_Framework_TestCase ...@@ -281,17 +266,6 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("bar", $table->getOption("foo")); $this->assertEquals("bar", $table->getOption("foo"));
} }
public function testIdGeneratorType()
{
$table = new Table("foo");
$table->setIdGeneratorType(Table::ID_IDENTITY);
$this->assertTrue($table->isIdGeneratorIdentity());
$table->setIdGeneratorType(Table::ID_SEQUENCE);
$this->assertTrue($table->isIdGeneratorSequence());
}
public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException()
{ {
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); $this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
......
...@@ -66,7 +66,6 @@ class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase ...@@ -66,7 +66,6 @@ class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
$tableA->addColumn("id", 'integer'); $tableA->addColumn("id", 'integer');
$tableA->addColumn("bar", 'string', array('length' => 255)); $tableA->addColumn("bar", 'string', array('length' => 255));
$tableA->setPrimaryKey(array("id")); $tableA->setPrimaryKey(array("id"));
$tableA->setIdGeneratorType(Table::ID_SEQUENCE);
$schema->createSequence("foo_seq"); $schema->createSequence("foo_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