Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Illuminate/Database/Schema/ColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @method $this default(mixed $value) Specify a "default" value for the column
* @method $this first() Place the column "first" in the table (MySQL)
* @method $this from(int $startingValue) Set the starting value of an auto-incrementing field (MySQL / PostgreSQL)
* @method $this instant() Specify that algorithm=instant should be used for the column operation (MySQL)
* @method $this generatedAs(string|\Illuminate\Contracts\Database\Query\Expression $expression = null) Create a SQL compliant identity column (PostgreSQL)
* @method $this index(bool|string $indexName = null) Add an index
* @method $this invisible() Specify that the column should be invisible to "SELECT *" (MySQL)
Expand Down
13 changes: 10 additions & 3 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,10 @@ protected function compileCreateEngine($sql, Blueprint $blueprint)
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
return sprintf('alter table %s add %s',
return sprintf('alter table %s add %s%s',
$this->wrapTable($blueprint),
$this->getColumn($blueprint, $command->column)
$this->getColumn($blueprint, $command->column),
$command->column->instant ? ', algorithm=instant' : ''
);
}

Expand Down Expand Up @@ -403,7 +404,13 @@ public function compileChange(Blueprint $blueprint, Fluent $command)
$this->getType($column)
);

return $this->addModifiers($sql, $blueprint, $column);
$sql = $this->addModifiers($sql, $blueprint, $column);

if ($column->instant) {
$sql .= ', algorithm=instant';
}

return $sql;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,26 @@ protected function getConnection(
->getMock();
}

public function testAddingColumnWithAlgorithm()
{
$blueprint = new Blueprint($this->getConnection(), 'users');
$blueprint->string('name')->instant();
$statements = $blueprint->toSql();

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add `name` varchar(255) not null, algorithm=instant', $statements[0]);
}

public function testChangingColumnWithAlgorithm()
{
$blueprint = new Blueprint($this->getConnection(), 'users');
$blueprint->string('name', 100)->change()->instant();
$statements = $blueprint->toSql();

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` modify `name` varchar(100) not null, algorithm=instant', $statements[0]);
}

public function getGrammar(?Connection $connection = null)
{
return new MySqlGrammar($connection ?? $this->getConnection());
Expand Down
Loading