Skip to content

Commit 89f9383

Browse files
authored
Merge pull request #6878 from morozov/remove-get-index-declaration-sql
Move MySQL-related code out of abstract platform
2 parents 2b3d652 + 92216d1 commit 89f9383

File tree

4 files changed

+14
-43
lines changed

4 files changed

+14
-43
lines changed

src/Platforms/AbstractMySQLPlatform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
414414
return array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
415415
}
416416

417+
/**
418+
* Returns the SQL fragment representing an index.
419+
*/
420+
private function getIndexDeclarationSQL(Index $index): string
421+
{
422+
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $index->getObjectName()->toSQL($this)
423+
. ' (' . implode(', ', $index->getQuotedColumns($this)) . ')';
424+
}
425+
417426
protected function getCreateIndexSQLFlags(Index $index): string
418427
{
419428
$type = '';

src/Platforms/AbstractPlatform.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,6 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
995995
$elements[] = $this->getPrimaryKeyConstraintDeclarationSQL($parameters['primaryKey']);
996996
}
997997

998-
foreach ($parameters['indexes'] as $definition) {
999-
$elements[] = $this->getIndexDeclarationSQL($definition);
1000-
}
1001-
1002998
$elements = array_merge($elements, $this->getCheckDeclarationSQL($columns));
1003999

10041000
$query = 'CREATE TABLE ' . $tableName->toSQL($this) . ' (' . implode(', ', $elements) . ')';
@@ -1447,26 +1443,6 @@ protected function getUniqueConstraintDeclarationSQL(UniqueConstraint $constrain
14471443
return implode(' ', $chunks);
14481444
}
14491445

1450-
/**
1451-
* Obtains DBMS specific SQL code portion needed to set an index
1452-
* declaration to be used in statements like CREATE TABLE.
1453-
*
1454-
* @param Index $index The index definition.
1455-
*
1456-
* @return string DBMS specific SQL code portion needed to set an index.
1457-
*/
1458-
protected function getIndexDeclarationSQL(Index $index): string
1459-
{
1460-
$columns = $index->getColumns();
1461-
1462-
if (count($columns) === 0) {
1463-
throw new InvalidArgumentException('Incomplete definition. "columns" required.');
1464-
}
1465-
1466-
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $index->getObjectName()->toSQL($this)
1467-
. ' (' . implode(', ', $index->getQuotedColumns($this)) . ')' . $this->getPartialIndexSQL($index);
1468-
}
1469-
14701446
/**
14711447
* Some vendors require temporary table names to be qualified specially.
14721448
*/

src/Platforms/DB2Platform.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,18 @@ public function getCurrentTimestampSQL(): string
241241
return 'CURRENT TIMESTAMP';
242242
}
243243

244-
protected function getIndexDeclarationSQL(Index $index): string
245-
{
246-
// Index declaration in statements like CREATE TABLE is not supported.
247-
throw NotSupported::new(__METHOD__);
248-
}
249-
250244
/**
251245
* {@inheritDoc}
252246
*/
253247
protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array $columns, array $parameters): array
254248
{
255-
$indexes = $parameters['indexes'];
256-
257-
$parameters['indexes'] = [];
258-
259-
$sqls = parent::_getCreateTableSQL($tableName, $columns, $parameters);
249+
$sql = parent::_getCreateTableSQL($tableName, $columns, $parameters);
260250

261-
foreach ($indexes as $definition) {
262-
$sqls[] = $this->getCreateIndexSQL($definition, $tableName->toSQL($this));
251+
foreach ($parameters['indexes'] as $index) {
252+
$sql[] = $this->getCreateIndexSQL($index, $tableName->toSQL($this));
263253
}
264254

265-
return $sqls;
255+
return $sql;
266256
}
267257

268258
/**

src/Platforms/OraclePlatform.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ public function getListSequencesSQL(string $database): string
319319
*/
320320
protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array $columns, array $parameters): array
321321
{
322-
$indexes = $parameters['indexes'];
323-
324-
$parameters['indexes'] = [];
325-
326322
$sql = parent::_getCreateTableSQL($tableName, $columns, $parameters);
327323

328324
foreach ($columns as $column) {
@@ -339,7 +335,7 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
339335
$sql = array_merge($sql, $this->getCreateAutoincrementSql($tableName, $column['name']));
340336
}
341337

342-
foreach ($indexes as $index) {
338+
foreach ($parameters['indexes'] as $index) {
343339
$sql[] = $this->getCreateIndexSQL($index, $tableName->toSQL($this));
344340
}
345341

0 commit comments

Comments
 (0)