@@ -298,22 +298,25 @@ public function addUniqueIndex(array $columnNames, ?string $indexName = null, ar
298
298
*/
299
299
public function renameIndex (string $ oldName , ?string $ newName = null ): self
300
300
{
301
- $ oldName = $ this ->normalizeIdentifier ($ oldName );
302
- $ normalizedNewName = $ this ->normalizeIdentifier ($ newName );
303
-
304
- if ($ oldName === $ normalizedNewName ) {
305
- return $ this ;
306
- }
307
-
308
301
if (! $ this ->hasIndex ($ oldName )) {
309
302
throw IndexDoesNotExist::new ($ oldName , $ this ->_name );
310
303
}
311
304
312
- if ($ this ->hasIndex ($ normalizedNewName )) {
313
- throw IndexAlreadyExists::new ($ normalizedNewName , $ this ->_name );
305
+ $ normalizedOldName = $ this ->normalizeIdentifier ($ oldName );
306
+
307
+ if ($ newName !== null ) {
308
+ $ normalizedNewName = $ this ->normalizeIdentifier ($ newName );
309
+
310
+ if ($ normalizedOldName === $ normalizedNewName ) {
311
+ return $ this ;
312
+ }
313
+
314
+ if ($ this ->hasIndex ($ newName )) {
315
+ throw IndexAlreadyExists::new ($ newName , $ this ->_name );
316
+ }
314
317
}
315
318
316
- $ oldIndex = $ this ->_indexes [$ oldName ];
319
+ $ oldIndex = $ this ->_indexes [$ normalizedOldName ];
317
320
318
321
if ($ oldIndex ->isPrimary ()) {
319
322
Deprecation::triggerIfCalledFromOutside (
@@ -329,7 +332,7 @@ public function renameIndex(string $oldName, ?string $newName = null): self
329
332
return $ this ->setPrimaryKey ($ oldIndex ->getColumns (), $ newName ?? null );
330
333
}
331
334
332
- unset($ this ->_indexes [$ oldName ]);
335
+ unset($ this ->_indexes [$ normalizedOldName ]);
333
336
334
337
if ($ oldIndex ->isUnique ()) {
335
338
return $ this ->addUniqueIndex ($ oldIndex ->getColumns (), $ newName , $ oldIndex ->getOptions ());
@@ -944,12 +947,8 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint): s
944
947
*
945
948
* Trims quotes and lowercases the given identifier.
946
949
*/
947
- private function normalizeIdentifier (? string $ identifier ): string
950
+ private function normalizeIdentifier (string $ identifier ): string
948
951
{
949
- if ($ identifier === null ) {
950
- return '' ;
951
- }
952
-
953
952
return $ this ->trimQuotes (strtolower ($ identifier ));
954
953
}
955
954
0 commit comments