1
0
mirror of synced 2024-12-13 06:46:03 +03:00

[2.0] DDC-169 - Added possibility to control which case mode schema assets are created with in SchemaManager

This commit is contained in:
beberlei 2009-12-04 21:58:16 +00:00
parent 556f8699ee
commit 70075d8f80
6 changed files with 67 additions and 79 deletions

View File

@ -55,6 +55,11 @@ abstract class AbstractSchemaManager
*/ */
protected $_platform; protected $_platform;
/**
* @var string
*/
protected $_caseMode = AbstractAsset::CASE_KEEP;
/** /**
* Constructor. Accepts the Connection instance to manage the schema for * Constructor. Accepts the Connection instance to manage the schema for
* *
@ -66,6 +71,22 @@ abstract class AbstractSchemaManager
$this->_platform = $this->_conn->getDatabasePlatform(); $this->_platform = $this->_conn->getDatabasePlatform();
} }
/**
* @param string $caseMode
*/
public function setCaseMode($caseMode)
{
$this->_caseMode = $caseMode;
}
/**
* @return string
*/
public function getCaseMode()
{
return $this->_caseMode;
}
/** /**
* Return associated platform. * Return associated platform.
* *
@ -267,7 +288,9 @@ abstract class AbstractSchemaManager
} }
} }
$tables[] = new Table($tableName, $columns, $indexes, $foreignKeys, $idGeneratorType, array()); $table = new Table($tableName, $columns, $indexes, $foreignKeys, $idGeneratorType, array());
$table->setCaseMode($this->_caseMode);
$tables[] = $table;
} }
return $tables; return $tables;
@ -905,6 +928,7 @@ abstract class AbstractSchemaManager
$indexes = array(); $indexes = array();
foreach($result AS $indexKey => $data) { foreach($result AS $indexKey => $data) {
$indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']); $indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
$indexes[$indexKey]->setCaseMode($this->_caseMode);
} }
return $indexes; return $indexes;
@ -994,6 +1018,9 @@ abstract class AbstractSchemaManager
} }
$tables = $this->listTables(); $tables = $this->listTables();
return new Schema($tables, $sequences); $schema = new Schema($tables, $sequences);
$schema->setCaseMode($this->_caseMode);
return $schema;
} }
} }

View File

@ -259,86 +259,23 @@ class MySqlSchemaManager extends AbstractSchemaManager
$options['precision'] = $precision; $options['precision'] = $precision;
} }
return new Column($tableColumn['Field'], \Doctrine\DBAL\Types\Type::getType($type), $options); $column = new Column($tableColumn['Field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
$column->setCaseMode($this->getCaseMode());
return $column;
} }
public function _getPortableTableForeignKeyDefinition($tableForeignKey) public function _getPortableTableForeignKeyDefinition($tableForeignKey)
{ {
$tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER); $tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
return new ForeignKeyConstraint( $fk = new ForeignKeyConstraint(
(array)$tableForeignKey['column_name'], (array)$tableForeignKey['column_name'],
$tableForeignKey['referenced_table_name'], $tableForeignKey['referenced_table_name'],
(array)$tableForeignKey['referenced_column_name'], (array)$tableForeignKey['referenced_column_name'],
$tableForeignKey['constraint_name'], $tableForeignKey['constraint_name'],
array() array()
); );
} $fk->setCaseMode($this->getCaseMode());
return $fk;
/**
* {@inheritdoc}
*/
public function createSequence($sequenceName, $start = 1, $allocationSize = 1)
{
$seqColumnName = 'mysql_sequence';
/* No support for options yet. Might add 4th options parameter later
$optionsStrings = array();
if (isset($options['comment']) && ! empty($options['comment'])) {
$optionsStrings['comment'] = 'COMMENT = ' . $this->_conn->quote($options['comment'], 'string');
}
if (isset($options['charset']) && ! empty($options['charset'])) {
$optionsStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
if (isset($options['collate'])) {
$optionsStrings['collate'] .= ' COLLATE ' . $options['collate'];
}
}
$type = false;
if (isset($options['type'])) {
$type = $options['type'];
} else {
$type = $this->_conn->default_table_type;
}
if ($type) {
$optionsStrings[] = 'ENGINE = ' . $type;
}*/
try {
$query = 'CREATE TABLE ' . $sequenceName
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcolName . '))';
/*if (!empty($options_strings)) {
$query .= ' '.implode(' ', $options_strings);
}*/
$query .= ' ENGINE = INNODB';
$res = $this->_conn->exec($query);
} catch(Doctrine\DBAL\ConnectionException $e) {
throw \Doctrine\Common\DoctrineException::createSequenceFailed($query);
}
if ($start == 1) {
return;
}
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
$res = $this->_conn->exec($query);
// Handle error
try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch (\Exception $e) {
throw \Doctrine\Common\DoctrineException::couldNotDropSequenceTable($sequenceName);
}
return $res;
} }
} }

View File

@ -189,7 +189,9 @@ class OracleSchemaManager extends AbstractSchemaManager
'platformDetails' => array(), 'platformDetails' => array(),
); );
return new Column($tableColumn['column_name'], \Doctrine\DBAL\Types\Type::getType($type), $options); $column = new Column($tableColumn['column_name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
$column->setCaseMode($this->getCaseMode());
return $column;
} }
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList($tableForeignKeys)
@ -212,11 +214,13 @@ class OracleSchemaManager extends AbstractSchemaManager
$result = array(); $result = array();
foreach($list AS $constraint) { foreach($list AS $constraint) {
$result[] = new ForeignKeyConstraint( $fk = new ForeignKeyConstraint(
array_values($constraint['local']), $constraint['foreignTable'], array_values($constraint['local']), $constraint['foreignTable'],
array_values($constraint['foreign']), $constraint['name'], array_values($constraint['foreign']), $constraint['name'],
array('onDelete' => $constraint['onDelete']) array('onDelete' => $constraint['onDelete'])
); );
$fk->setCaseMode($this->getCaseMode());
$result[] = $fk;
} }
return $result; return $result;
@ -225,7 +229,9 @@ class OracleSchemaManager extends AbstractSchemaManager
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition($sequence)
{ {
$sequence = \array_change_key_case($sequence, CASE_LOWER); $sequence = \array_change_key_case($sequence, CASE_LOWER);
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['min_value']); $sequence = new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['min_value']);
$sequence->setCaseMode($this->getCaseMode());
return $sequence;
} }
protected function _getPortableTableConstraintDefinition($tableConstraint) protected function _getPortableTableConstraintDefinition($tableConstraint)

View File

@ -51,10 +51,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$foreignTable = $values[2]; $foreignTable = $values[2];
} }
return new ForeignKeyConstraint( $fk = new ForeignKeyConstraint(
$localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'], $localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'],
array('onUpdate' => $onUpdate, 'onDelete' => $onDelete) array('onUpdate' => $onUpdate, 'onDelete' => $onDelete)
); );
$fk->setCaseMode($this->getCaseMode());
return $fk;
} }
public function dropDatabase($database) public function dropDatabase($database)
@ -154,7 +156,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition($sequence)
{ {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM '.$sequence['relname']); $data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM '.$sequence['relname']);
return new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']); $sequence = new Sequence($sequence['relname'], $data[0]['increment_by'], $data[0]['min_value']);
$sequence->setCaseMode($this->getCaseMode());
return $sequence;
} }
protected function _getPortableTableConstraintDefinition($tableConstraint) protected function _getPortableTableConstraintDefinition($tableConstraint)
@ -330,6 +334,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
), ),
); );
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options); $column = new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
$column->setCaseMode($this->getCaseMode());
return $column;
} }
} }

View File

@ -255,6 +255,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
), ),
); );
return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options); $column = new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
$column->setCaseMode($this->getCaseMode());
return $column;
} }
} }

View File

@ -8,8 +8,19 @@ use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
/**
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $_sm = null; protected $_sm = null;
public function setUp()
{
parent::setUp();
$this->_sm = $this->_em->getConnection()->getSchemaManager();
$this->_sm->setCaseMode("lower");
}
public function testCreateSimpleYamlFromDatabase() public function testCreateSimpleYamlFromDatabase()
{ {
$table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo"); $table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo");
@ -17,7 +28,6 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$table->createColumn('bar', 'string', array('length' => 200)); $table->createColumn('bar', 'string', array('length' => 200));
$this->_sm = $this->_em->getConnection()->getSchemaManager();
$this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateTable($table);
$this->assertClassMetadataYamlEqualsFile(__DIR__."/DatabaseDriver/simpleYaml.yml", "DbdriverFoo"); $this->assertClassMetadataYamlEqualsFile(__DIR__."/DatabaseDriver/simpleYaml.yml", "DbdriverFoo");