Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mtawil authored Dec 14, 2023
1 parent 4994754 commit 0c763c1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ protected function compileCreateTable($blueprint, $command, $connection)
$tableStructure = $this->getColumns($blueprint);

if ($primaryKey = $this->getCommandByName($blueprint, 'primary')) {
$tableStructure[] = $this->compilePrimary($blueprint, $primaryKey);
$tableStructure[] = sprintf('primary key %s(%s)',
$primaryKey->algorithm ? 'using '.$primaryKey->algorithm : '',
$this->columnize($primaryKey->columns)
);

// Prevents redundant alteration of the primary key.
unset($primaryKey['name']);
Expand Down Expand Up @@ -403,13 +406,6 @@ public function compileChange(Blueprint $blueprint, Fluent $command, Connection
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
if ($blueprint->creating()) {
return sprintf('primary key %s(%s)',
$command->algorithm ? 'using '.$command->algorithm : '',
$this->columnize($command->columns)
);
}

return sprintf('alter table %s add primary key %s(%s)',
$this->wrapTable($blueprint),
$command->algorithm ? 'using '.$command->algorithm : '',
Expand Down

0 comments on commit 0c763c1

Please sign in to comment.