Skip to content

Commit

Permalink
remove index name when adding primary key on MySQL (#45515)
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari authored Jan 6, 2023
1 parent b1622d6 commit a615378
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
$command->name(null);

return $this->compileKey($blueprint, $command, 'primary key');
return sprintf('alter table %s add primary key %s(%s)',
$this->wrapTable($blueprint),
$command->algorithm ? 'using '.$command->algorithm : '',
$this->columnize($command->columns)
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function testAddingPrimaryKey()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add primary key `bar`(`foo`)', $statements[0]);
$this->assertSame('alter table `users` add primary key (`foo`)', $statements[0]);
}

public function testAddingPrimaryKeyWithAlgorithm()
Expand All @@ -329,7 +329,7 @@ public function testAddingPrimaryKeyWithAlgorithm()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add primary key `bar` using hash(`foo`)', $statements[0]);
$this->assertSame('alter table `users` add primary key using hash(`foo`)', $statements[0]);
}

public function testAddingUniqueKey()
Expand Down

0 comments on commit a615378

Please sign in to comment.