quote index columns on oracle, handle all index changes, minor phpdoc cleanup
This commit is contained in:
parent
c8323f822d
commit
d081a1a5ad
|
@ -32,20 +32,15 @@ use Doctrine\DBAL\Schema\Schema;
|
|||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
class OracleMigrator extends NoCheckMigrator {
|
||||
/**
|
||||
* @param Schema $targetSchema
|
||||
* @param \Doctrine\DBAL\Connection $connection
|
||||
* @return \Doctrine\DBAL\Schema\SchemaDiff
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
|
||||
$schemaDiff = parent::getDiff($targetSchema, $connection);
|
||||
|
||||
// oracle forces us to quote the identifiers
|
||||
$schemaDiff->newTables = array_map(function(Table $table) {
|
||||
return new Table(
|
||||
$this->connection->quoteIdentifier($table->getName()),
|
||||
array_map(function(Column $column) {
|
||||
/**
|
||||
* 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()
|
||||
|
@ -63,10 +58,19 @@ class OracleMigrator extends NoCheckMigrator {
|
|||
$newColumn->setPlatformOptions($column->getPlatformOptions());
|
||||
$newColumn->setCustomSchemaOptions($column->getPlatformOptions());
|
||||
return $newColumn;
|
||||
}, $table->getColumns()),
|
||||
array_map(function(Index $index) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
$this->connection->quoteIdentifier($index->getName()),
|
||||
//TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
|
||||
$index->getName(),
|
||||
array_map(function($columnName) {
|
||||
return $this->connection->quoteIdentifier($columnName);
|
||||
}, $index->getColumns()),
|
||||
|
@ -75,6 +79,26 @@ class OracleMigrator extends NoCheckMigrator {
|
|||
$index->getFlags(),
|
||||
$index->getOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $targetSchema
|
||||
* @param \Doctrine\DBAL\Connection $connection
|
||||
* @return \Doctrine\DBAL\Schema\SchemaDiff
|
||||
* @throws DBALException
|
||||
*/
|
||||
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
|
||||
$schemaDiff = parent::getDiff($targetSchema, $connection);
|
||||
|
||||
// oracle forces us to quote the identifiers
|
||||
$schemaDiff->newTables = array_map(function(Table $table) {
|
||||
return new Table(
|
||||
$this->connection->quoteIdentifier($table->getName()),
|
||||
array_map(function(Column $column) {
|
||||
return $this->quoteColumn($column);
|
||||
}, $table->getColumns()),
|
||||
array_map(function(Index $index) {
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue