Commit 70075d8f authored by beberlei's avatar beberlei

[2.0] DDC-169 - Added possibility to control which case mode schema assets are...

[2.0] DDC-169 - Added possibility to control which case mode schema assets are created with in SchemaManager
parent 556f8699
......@@ -55,6 +55,11 @@ abstract class AbstractSchemaManager
*/
protected $_platform;
/**
* @var string
*/
protected $_caseMode = AbstractAsset::CASE_KEEP;
/**
* Constructor. Accepts the Connection instance to manage the schema for
*
......@@ -66,6 +71,22 @@ abstract class AbstractSchemaManager
$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.
*
......@@ -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;
......@@ -905,6 +928,7 @@ abstract class AbstractSchemaManager
$indexes = array();
foreach($result AS $indexKey => $data) {
$indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
$indexes[$indexKey]->setCaseMode($this->_caseMode);
}
return $indexes;
......@@ -994,6 +1018,9 @@ abstract class AbstractSchemaManager
}
$tables = $this->listTables();
return new Schema($tables, $sequences);
$schema = new Schema($tables, $sequences);
$schema->setCaseMode($this->_caseMode);
return $schema;
}
}
\ No newline at end of file
......@@ -259,86 +259,23 @@ class MySqlSchemaManager extends AbstractSchemaManager
$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)
{
$tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
return new ForeignKeyConstraint(
$fk = new ForeignKeyConstraint(
(array)$tableForeignKey['column_name'],
$tableForeignKey['referenced_table_name'],
(array)$tableForeignKey['referenced_column_name'],
$tableForeignKey['constraint_name'],
array()
);
}
/**
* {@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;
$fk->setCaseMode($this->getCaseMode());
return $fk;
}
}
\ No newline at end of file
......@@ -189,7 +189,9 @@ class OracleSchemaManager extends AbstractSchemaManager
'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)
......@@ -212,11 +214,13 @@ class OracleSchemaManager extends AbstractSchemaManager
$result = array();
foreach($list AS $constraint) {
$result[] = new ForeignKeyConstraint(
$fk = new ForeignKeyConstraint(
array_values($constraint['local']), $constraint['foreignTable'],
array_values($constraint['foreign']), $constraint['name'],
array('onDelete' => $constraint['onDelete'])
);
$fk->setCaseMode($this->getCaseMode());
$result[] = $fk;
}
return $result;
......@@ -225,7 +229,9 @@ class OracleSchemaManager extends AbstractSchemaManager
protected function _getPortableSequenceDefinition($sequence)
{
$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)
......
......@@ -51,10 +51,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$foreignTable = $values[2];
}
return new ForeignKeyConstraint(
$fk = new ForeignKeyConstraint(
$localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'],
array('onUpdate' => $onUpdate, 'onDelete' => $onDelete)
);
$fk->setCaseMode($this->getCaseMode());
return $fk;
}
public function dropDatabase($database)
......@@ -154,7 +156,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected function _getPortableSequenceDefinition($sequence)
{
$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)
......@@ -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;
}
}
\ No newline at end of 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;
}
}
\ No newline at end of file
......@@ -8,8 +8,19 @@ use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
/**
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $_sm = null;
public function setUp()
{
parent::setUp();
$this->_sm = $this->_em->getConnection()->getSchemaManager();
$this->_sm->setCaseMode("lower");
}
public function testCreateSimpleYamlFromDatabase()
{
$table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo");
......@@ -17,7 +28,6 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$table->setPrimaryKey(array('id'));
$table->createColumn('bar', 'string', array('length' => 200));
$this->_sm = $this->_em->getConnection()->getSchemaManager();
$this->_sm->dropAndCreateTable($table);
$this->assertClassMetadataYamlEqualsFile(__DIR__."/DatabaseDriver/simpleYaml.yml", "DbdriverFoo");
......
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