Skip to content

Commit b7a05ef

Browse files
committed
Try new methods without manually quoting?
Signed-off-by: Joas Schilling <[email protected]>
1 parent 3cc8dac commit b7a05ef

File tree

1 file changed

+163
-163
lines changed

1 file changed

+163
-163
lines changed

lib/private/DB/OracleMigrator.php

Lines changed: 163 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -37,169 +37,169 @@
3737
use Doctrine\DBAL\Schema\Table;
3838

3939
class OracleMigrator extends Migrator {
40-
// /**
41-
// * Quote a column's name but changing the name requires recreating
42-
// * the column instance and copying over all properties.
43-
// *
44-
// * @param Column $column old column
45-
// * @return Column new column instance with new name
46-
// */
47-
// protected function quoteColumn(Column $column) {
48-
// $newColumn = new Column(
49-
// $this->connection->quoteIdentifier($column->getName()),
50-
// $column->getType()
51-
// );
52-
// $newColumn->setAutoincrement($column->getAutoincrement());
53-
// $newColumn->setColumnDefinition($column->getColumnDefinition());
54-
// $newColumn->setComment($column->getComment());
55-
// $newColumn->setDefault($column->getDefault());
56-
// $newColumn->setFixed($column->getFixed());
57-
// $newColumn->setLength($column->getLength());
58-
// $newColumn->setNotnull($column->getNotnull());
59-
// $newColumn->setPrecision($column->getPrecision());
60-
// $newColumn->setScale($column->getScale());
61-
// $newColumn->setUnsigned($column->getUnsigned());
62-
// $newColumn->setPlatformOptions($column->getPlatformOptions());
63-
// $newColumn->setCustomSchemaOptions($column->getPlatformOptions());
64-
// return $newColumn;
65-
// }
66-
//
67-
// /**
68-
// * Quote an index's name but changing the name requires recreating
69-
// * the index instance and copying over all properties.
70-
// *
71-
// * @param Index $index old index
72-
// * @return Index new index instance with new name
73-
// */
74-
// protected function quoteIndex($index) {
75-
// return new Index(
76-
// //TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
77-
// $index->getName(),
78-
// array_map(function ($columnName) {
79-
// return $this->connection->quoteIdentifier($columnName);
80-
// }, $index->getColumns()),
81-
// $index->isUnique(),
82-
// $index->isPrimary(),
83-
// $index->getFlags(),
84-
// $index->getOptions()
85-
// );
86-
// }
87-
//
88-
// /**
89-
// * Quote an ForeignKeyConstraint's name but changing the name requires recreating
90-
// * the ForeignKeyConstraint instance and copying over all properties.
91-
// *
92-
// * @param ForeignKeyConstraint $fkc old fkc
93-
// * @return ForeignKeyConstraint new fkc instance with new name
94-
// */
95-
// protected function quoteForeignKeyConstraint($fkc) {
96-
// return new ForeignKeyConstraint(
97-
// array_map(function ($columnName) {
98-
// return $this->connection->quoteIdentifier($columnName);
99-
// }, $fkc->getLocalColumns()),
100-
// $this->connection->quoteIdentifier($fkc->getForeignTableName()),
101-
// array_map(function ($columnName) {
102-
// return $this->connection->quoteIdentifier($columnName);
103-
// }, $fkc->getForeignColumns()),
104-
// $fkc->getName(),
105-
// $fkc->getOptions()
106-
// );
107-
// }
108-
//
109-
// /**
110-
// * @param Schema $targetSchema
111-
// * @param \Doctrine\DBAL\Connection $connection
112-
// * @return \Doctrine\DBAL\Schema\SchemaDiff
113-
// * @throws Exception
114-
// */
115-
// protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
116-
// $schemaDiff = parent::getDiff($targetSchema, $connection);
117-
//
118-
// // oracle forces us to quote the identifiers
119-
// $schemaDiff->newTables = array_map(function (Table $table) {
120-
// return new Table(
121-
// $this->connection->quoteIdentifier($table->getName()),
122-
// array_map(function (Column $column) {
123-
// return $this->quoteColumn($column);
124-
// }, $table->getColumns()),
125-
// array_map(function (Index $index) {
126-
// return $this->quoteIndex($index);
127-
// }, $table->getIndexes()),
128-
// [],
129-
// array_map(function (ForeignKeyConstraint $fck) {
130-
// return $this->quoteForeignKeyConstraint($fck);
131-
// }, $table->getForeignKeys()),
132-
// $table->getOptions()
133-
// );
134-
// }, $schemaDiff->newTables);
135-
//
136-
// $schemaDiff->removedTables = array_map(function (Table $table) {
137-
// return new Table(
138-
// $this->connection->quoteIdentifier($table->getName()),
139-
// $table->getColumns(),
140-
// $table->getIndexes(),
141-
// [],
142-
// $table->getForeignKeys(),
143-
// $table->getOptions()
144-
// );
145-
// }, $schemaDiff->removedTables);
146-
//
147-
// foreach ($schemaDiff->changedTables as $tableDiff) {
148-
// $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
149-
//
150-
// $tableDiff->addedColumns = array_map(function (Column $column) {
151-
// return $this->quoteColumn($column);
152-
// }, $tableDiff->addedColumns);
153-
//
154-
// foreach ($tableDiff->changedColumns as $column) {
155-
// $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
156-
// // auto increment is not relevant for oracle and can anyhow not be applied on change
157-
// $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
158-
// }
159-
// // remove columns that no longer have changed (because autoincrement and unsigned are not supported)
160-
// $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
161-
// return count($column->changedProperties) > 0;
162-
// });
163-
//
164-
// $tableDiff->removedColumns = array_map(function (Column $column) {
165-
// return $this->quoteColumn($column);
166-
// }, $tableDiff->removedColumns);
167-
//
168-
// $tableDiff->renamedColumns = array_map(function (Column $column) {
169-
// return $this->quoteColumn($column);
170-
// }, $tableDiff->renamedColumns);
171-
//
172-
// $tableDiff->addedIndexes = array_map(function (Index $index) {
173-
// return $this->quoteIndex($index);
174-
// }, $tableDiff->addedIndexes);
175-
//
176-
// $tableDiff->changedIndexes = array_map(function (Index $index) {
177-
// return $this->quoteIndex($index);
178-
// }, $tableDiff->changedIndexes);
179-
//
180-
// $tableDiff->removedIndexes = array_map(function (Index $index) {
181-
// return $this->quoteIndex($index);
182-
// }, $tableDiff->removedIndexes);
183-
//
184-
// $tableDiff->renamedIndexes = array_map(function (Index $index) {
185-
// return $this->quoteIndex($index);
186-
// }, $tableDiff->renamedIndexes);
187-
//
188-
// $tableDiff->addedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
189-
// return $this->quoteForeignKeyConstraint($fkc);
190-
// }, $tableDiff->addedForeignKeys);
191-
//
192-
// $tableDiff->changedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
193-
// return $this->quoteForeignKeyConstraint($fkc);
194-
// }, $tableDiff->changedForeignKeys);
195-
//
196-
// $tableDiff->removedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
197-
// return $this->quoteForeignKeyConstraint($fkc);
198-
// }, $tableDiff->removedForeignKeys);
199-
// }
200-
//
201-
// return $schemaDiff;
202-
// }
40+
/**
41+
* Quote a column's name but changing the name requires recreating
42+
* the column instance and copying over all properties.
43+
*
44+
* @param Column $column old column
45+
* @return Column new column instance with new name
46+
*/
47+
protected function quoteColumn(Column $column) {
48+
$newColumn = new Column(
49+
$this->connection->quoteIdentifier($column->getName()),
50+
$column->getType()
51+
);
52+
$newColumn->setAutoincrement($column->getAutoincrement());
53+
$newColumn->setColumnDefinition($column->getColumnDefinition());
54+
$newColumn->setComment($column->getComment());
55+
$newColumn->setDefault($column->getDefault());
56+
$newColumn->setFixed($column->getFixed());
57+
$newColumn->setLength($column->getLength());
58+
$newColumn->setNotnull($column->getNotnull());
59+
$newColumn->setPrecision($column->getPrecision());
60+
$newColumn->setScale($column->getScale());
61+
$newColumn->setUnsigned($column->getUnsigned());
62+
$newColumn->setPlatformOptions($column->getPlatformOptions());
63+
$newColumn->setCustomSchemaOptions($column->getPlatformOptions());
64+
return $newColumn;
65+
}
66+
67+
/**
68+
* Quote an index's name but changing the name requires recreating
69+
* the index instance and copying over all properties.
70+
*
71+
* @param Index $index old index
72+
* @return Index new index instance with new name
73+
*/
74+
protected function quoteIndex($index) {
75+
return new Index(
76+
//TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()),
77+
$index->getName(),
78+
array_map(function ($columnName) {
79+
return $this->connection->quoteIdentifier($columnName);
80+
}, $index->getColumns()),
81+
$index->isUnique(),
82+
$index->isPrimary(),
83+
$index->getFlags(),
84+
$index->getOptions()
85+
);
86+
}
87+
88+
/**
89+
* Quote an ForeignKeyConstraint's name but changing the name requires recreating
90+
* the ForeignKeyConstraint instance and copying over all properties.
91+
*
92+
* @param ForeignKeyConstraint $fkc old fkc
93+
* @return ForeignKeyConstraint new fkc instance with new name
94+
*/
95+
protected function quoteForeignKeyConstraint($fkc) {
96+
return new ForeignKeyConstraint(
97+
array_map(function ($columnName) {
98+
return $this->connection->quoteIdentifier($columnName);
99+
}, $fkc->getLocalColumns()),
100+
$this->connection->quoteIdentifier($fkc->getForeignTableName()),
101+
array_map(function ($columnName) {
102+
return $this->connection->quoteIdentifier($columnName);
103+
}, $fkc->getForeignColumns()),
104+
$fkc->getName(),
105+
$fkc->getOptions()
106+
);
107+
}
108+
109+
/**
110+
* @param Schema $targetSchema
111+
* @param \Doctrine\DBAL\Connection $connection
112+
* @return \Doctrine\DBAL\Schema\SchemaDiff
113+
* @throws Exception
114+
*/
115+
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
116+
$schemaDiff = parent::getDiff($targetSchema, $connection);
117+
118+
// oracle forces us to quote the identifiers
119+
$schemaDiff->newTables = array_map(function (Table $table) {
120+
return new Table(
121+
$table->getName(),
122+
array_map(function (Column $column) {
123+
return $this->quoteColumn($column);
124+
}, $table->getColumns()),
125+
array_map(function (Index $index) {
126+
return $this->quoteIndex($index);
127+
}, $table->getIndexes()),
128+
[],
129+
array_map(function (ForeignKeyConstraint $fck) {
130+
return $this->quoteForeignKeyConstraint($fck);
131+
}, $table->getForeignKeys()),
132+
$table->getOptions()
133+
);
134+
}, $schemaDiff->getCreatedTables());
135+
136+
$schemaDiff->removedTables = array_map(function (Table $table) {
137+
return new Table(
138+
$this->connection->quoteIdentifier($table->getName()),
139+
$table->getColumns(),
140+
$table->getIndexes(),
141+
[],
142+
$table->getForeignKeys(),
143+
$table->getOptions()
144+
);
145+
}, $schemaDiff->getDroppedTables());
146+
147+
foreach ($schemaDiff->getAlteredTables() as $tableDiff) {
148+
$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
149+
150+
$tableDiff->addedColumns = array_map(function (Column $column) {
151+
return $this->quoteColumn($column);
152+
}, $tableDiff->addedColumns);
153+
154+
foreach ($tableDiff->changedColumns as $column) {
155+
$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
156+
// auto increment is not relevant for oracle and can anyhow not be applied on change
157+
$column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
158+
}
159+
// remove columns that no longer have changed (because autoincrement and unsigned are not supported)
160+
$tableDiff->changedColumns = array_filter($tableDiff->getModifiedColumns(), function (ColumnDiff $column) {
161+
return count($column->changedProperties) > 0;
162+
});
163+
164+
$tableDiff->removedColumns = array_map(function (Column $column) {
165+
return $this->quoteColumn($column);
166+
}, $tableDiff->getDroppedColumns());
167+
168+
$tableDiff->renamedColumns = array_map(function (Column $column) {
169+
return $this->quoteColumn($column);
170+
}, $tableDiff->getRenamedColumns());
171+
172+
$tableDiff->addedIndexes = array_map(function (Index $index) {
173+
return $this->quoteIndex($index);
174+
}, $tableDiff->getAddedIndexes());
175+
176+
$tableDiff->changedIndexes = array_map(function (Index $index) {
177+
return $this->quoteIndex($index);
178+
}, $tableDiff->getModifiedIndexes());
179+
180+
$tableDiff->removedIndexes = array_map(function (Index $index) {
181+
return $this->quoteIndex($index);
182+
}, $tableDiff->getDroppedIndexes());
183+
184+
$tableDiff->renamedIndexes = array_map(function (Index $index) {
185+
return $this->quoteIndex($index);
186+
}, $tableDiff->getRenamedIndexes());
187+
188+
$tableDiff->addedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
189+
return $this->quoteForeignKeyConstraint($fkc);
190+
}, $tableDiff->getAddedForeignKeys());
191+
192+
$tableDiff->changedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
193+
return $this->quoteForeignKeyConstraint($fkc);
194+
}, $tableDiff->getModifiedForeignKeys());
195+
196+
$tableDiff->removedForeignKeys = array_map(function (ForeignKeyConstraint $fkc) {
197+
return $this->quoteForeignKeyConstraint($fkc);
198+
}, $tableDiff->getDroppedForeignKeys());
199+
}
200+
201+
return $schemaDiff;
202+
}
203203

204204
/**
205205
* @param $statement

0 commit comments

Comments
 (0)