quote index columns on oracle, handle all index changes, minor phpdoc cleanup
This commit is contained in:
parent
c8323f822d
commit
d081a1a5ad
|
@ -32,6 +32,55 @@ use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\DBAL\Schema\Table;
|
use Doctrine\DBAL\Schema\Table;
|
||||||
|
|
||||||
class OracleMigrator extends NoCheckMigrator {
|
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 Schema $targetSchema
|
||||||
* @param \Doctrine\DBAL\Connection $connection
|
* @param \Doctrine\DBAL\Connection $connection
|
||||||
|
@ -46,35 +95,10 @@ class OracleMigrator extends NoCheckMigrator {
|
||||||
return new Table(
|
return new Table(
|
||||||
$this->connection->quoteIdentifier($table->getName()),
|
$this->connection->quoteIdentifier($table->getName()),
|
||||||
array_map(function(Column $column) {
|
array_map(function(Column $column) {
|
||||||
$newColumn = new Column(
|
return $this->quoteColumn($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;
|
|
||||||
}, $table->getColumns()),
|
}, $table->getColumns()),
|
||||||
array_map(function(Index $index) {
|
array_map(function(Index $index) {
|
||||||
return new Index(
|
return $this->quoteIndex($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()
|
|
||||||
);
|
|
||||||
}, $table->getIndexes()),
|
}, $table->getIndexes()),
|
||||||
$table->getForeignKeys(),
|
$table->getForeignKeys(),
|
||||||
0,
|
0,
|
||||||
|
@ -95,14 +119,48 @@ class OracleMigrator extends NoCheckMigrator {
|
||||||
|
|
||||||
foreach ($schemaDiff->changedTables as $tableDiff) {
|
foreach ($schemaDiff->changedTables as $tableDiff) {
|
||||||
$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
|
$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) {
|
foreach ($tableDiff->changedColumns as $column) {
|
||||||
$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
|
$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
|
||||||
// auto increment is not relevant for oracle and can anyhow not be applied on change
|
// auto increment is not relevant for oracle and can anyhow not be applied on change
|
||||||
$column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
|
$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) {
|
$tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
|
||||||
return count($column->changedProperties) > 0;
|
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;
|
return $schemaDiff;
|
||||||
|
|
Loading…
Reference in New Issue