diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index 8f5b710..c2d2ed1 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -276,10 +276,12 @@ protected function createKeysSql($spec) { $keys = array(); if (!empty($spec['primary key'])) { - $keys[] = 'PRIMARY KEY (' . $this->createKeySql($spec['primary key']) . ')'; + $primary_key = $this->getNormalizedIndexes($spec, 'primary key'); + $keys[] = 'PRIMARY KEY (' . $this->createKeySql($primary_key) . ')'; } if (!empty($spec['unique keys'])) { - foreach ($spec['unique keys'] as $key => $fields) { + $unique_keys = $this->getNormalizedIndexes($spec, 'unique keys'); + foreach ($unique_keys as $key => $fields) { $keys[] = 'UNIQUE KEY `' . $key . '` (' . $this->createKeySql($fields) . ')'; } } @@ -301,12 +303,15 @@ protected function createKeysSql($spec) { * * @param $spec * The table specification. + * @param string $index_type + * The index type. Defaults to 'indexes', but can also be 'unique keys' or + * 'primary key'. * * @return array * List of shortened indexes. */ - protected function getNormalizedIndexes($spec) { - $indexes = $spec['indexes']; + protected function getNormalizedIndexes($spec, $index_type = 'indexes') { + $indexes = $index_type === 'primary key' ? ['primary key' => $spec[$index_type]] : $spec[$index_type]; foreach ($indexes as $index_name => $index_fields) { foreach ($index_fields as $index_key => $index_field) { // Get the name of the field from the index specification. @@ -325,7 +330,7 @@ protected function getNormalizedIndexes($spec) { } } } - return $indexes; + return $index_type === 'primary key' ? $indexes['primary key'] : $indexes; } /**