quote index columns on oracle, handle all index changes, minor phpdoc cleanup

This commit is contained in:
Jörn Friedrich Dreyer 2017-04-20 15:55:30 +02:00 committed by Joas Schilling
parent c8323f822d
commit d081a1a5ad
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 85 additions and 27 deletions

View File

@ -32,6 +32,55 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
class OracleMigrator extends NoCheckMigrator {
/**
* Quote a column's name but changing the name requires recreating
* the column instance and copying over all properties.
*
* @param Column $column old column
* @return Column new column instance with new name
*/
protected function quoteColumn(Column $column) {
$newColumn = new Column(
$this->connection->quoteIdentifier($column->getName()),
$column->getType()
);
$newColumn->setAutoincrement($column->getAutoincrement());
$newColumn->setColumnDefinition($column->getColumnDefinition());
$newColumn->setComment($column->getComment());
$newColumn->setDefault($column->getDefault());
$newColumn->setFixed($column->getFixed());
$newColumn->setLength($column->getLength());
$newColumn->setNotnull($column->getNotnull());
$newColumn->setPrecision($column->getPrecision());
$newColumn->setScale($column->getScale());
$newColumn->setUnsigned($column->getUnsigned());
$newColumn->setPlatformOptions($column->getPlatformOptions());
$newColumn->setCustomSchemaOptions($column->getPlatformOptions());
return $newColumn;
}
/**
* Quote an index's name but changing the name requires recreating
* the index instance and copying over all properties.
*
* @param Index $index old index
* @return Index new index instance with new name
*/
protected function quoteIndex($index) {
return new Index(
//TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
$index->getName(),
array_map(function($columnName) {
return $this->connection->quoteIdentifier($columnName);
}, $index->getColumns()),
$index->isUnique(),
$index->isPrimary(),
$index->getFlags(),
$index->getOptions()
);
}
/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
@ -46,35 +95,10 @@ class OracleMigrator extends NoCheckMigrator {
return new Table(
$this->connection->quoteIdentifier($table->getName()),
array_map(function(Column $column) {
$newColumn = new Column(
$this->connection->quoteIdentifier($column->getName()),
$column->getType()
);
$newColumn->setAutoincrement($column->getAutoincrement());
$newColumn->setColumnDefinition($column->getColumnDefinition());
$newColumn->setComment($column->getComment());
$newColumn->setDefault($column->getDefault());
$newColumn->setFixed($column->getFixed());
$newColumn->setLength($column->getLength());
$newColumn->setNotnull($column->getNotnull());
$newColumn->setPrecision($column->getPrecision());
$newColumn->setScale($column->getScale());
$newColumn->setUnsigned($column->getUnsigned());
$newColumn->setPlatformOptions($column->getPlatformOptions());
$newColumn->setCustomSchemaOptions($column->getPlatformOptions());
return $newColumn;
return $this->quoteColumn($column);
}, $table->getColumns()),
array_map(function(Index $index) {
return new Index(
$this->connection->quoteIdentifier($index->getName()),
array_map(function($columnName) {
return $this->connection->quoteIdentifier($columnName);
}, $index->getColumns()),
$index->isUnique(),
$index->isPrimary(),
$index->getFlags(),
$index->getOptions()
);
return $this->quoteIndex($index);
}, $table->getIndexes()),
$table->getForeignKeys(),
0,
@ -95,14 +119,48 @@ class OracleMigrator extends NoCheckMigrator {
foreach ($schemaDiff->changedTables as $tableDiff) {
$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
$tableDiff->addedColumns = array_map(function(Column $column) {
return $this->quoteColumn($column);
}, $tableDiff->addedColumns);
foreach ($tableDiff->changedColumns as $column) {
$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
// auto increment is not relevant for oracle and can anyhow not be applied on change
$column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
}
// remove columns that no longer have changed (because autoincrement and unsigned are not supported)
$tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
return count($column->changedProperties) > 0;
});
$tableDiff->removedColumns = array_map(function(Column $column) {
return $this->quoteColumn($column);
}, $tableDiff->removedColumns);
$tableDiff->renamedColumns = array_map(function(Column $column) {
return $this->quoteColumn($column);
}, $tableDiff->renamedColumns);
$tableDiff->addedIndexes = array_map(function(Index $index) {
return $this->quoteIndex($index);
}, $tableDiff->addedIndexes);
$tableDiff->changedIndexes = array_map(function(Index $index) {
return $this->quoteIndex($index);
}, $tableDiff->changedIndexes);
$tableDiff->removedIndexes = array_map(function(Index $index) {
return $this->quoteIndex($index);
}, $tableDiff->removedIndexes);
$tableDiff->renamedIndexes = array_map(function(Index $index) {
return $this->quoteIndex($index);
}, $tableDiff->renamedIndexes);
// TODO handle $tableDiff->addedForeignKeys
// TODO handle $tableDiff->changedForeignKeys
// TODO handle $tableDiff->removedForeignKeys
}
return $schemaDiff;