Skip to content

Commit c90a957

Browse files
authored
add support for instant column additions (#57907)
1 parent ce385f8 commit c90a957

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/Illuminate/Database/Schema/ColumnDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @method $this default(mixed $value) Specify a "default" value for the column
1616
* @method $this first() Place the column "first" in the table (MySQL)
1717
* @method $this from(int $startingValue) Set the starting value of an auto-incrementing field (MySQL / PostgreSQL)
18+
* @method $this instant() Specify that algorithm=instant should be used for the column operation (MySQL)
1819
* @method $this generatedAs(string|\Illuminate\Contracts\Database\Query\Expression $expression = null) Create a SQL compliant identity column (PostgreSQL)
1920
* @method $this index(bool|string $indexName = null) Add an index
2021
* @method $this invisible() Specify that the column should be invisible to "SELECT *" (MySQL)

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ protected function compileCreateEngine($sql, Blueprint $blueprint)
310310
*/
311311
public function compileAdd(Blueprint $blueprint, Fluent $command)
312312
{
313-
return sprintf('alter table %s add %s',
313+
return sprintf('alter table %s add %s%s',
314314
$this->wrapTable($blueprint),
315-
$this->getColumn($blueprint, $command->column)
315+
$this->getColumn($blueprint, $command->column),
316+
$command->column->instant ? ', algorithm=instant' : ''
316317
);
317318
}
318319

@@ -403,7 +404,13 @@ public function compileChange(Blueprint $blueprint, Fluent $command)
403404
$this->getType($column)
404405
);
405406

406-
return $this->addModifiers($sql, $blueprint, $column);
407+
$sql = $this->addModifiers($sql, $blueprint, $column);
408+
409+
if ($column->instant) {
410+
$sql .= ', algorithm=instant';
411+
}
412+
413+
return $sql;
407414
}
408415

409416
/**

tests/Database/DatabaseMySqlSchemaGrammarTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,26 @@ protected function getConnection(
16041604
->getMock();
16051605
}
16061606

1607+
public function testAddingColumnWithAlgorithm()
1608+
{
1609+
$blueprint = new Blueprint($this->getConnection(), 'users');
1610+
$blueprint->string('name')->instant();
1611+
$statements = $blueprint->toSql();
1612+
1613+
$this->assertCount(1, $statements);
1614+
$this->assertSame('alter table `users` add `name` varchar(255) not null, algorithm=instant', $statements[0]);
1615+
}
1616+
1617+
public function testChangingColumnWithAlgorithm()
1618+
{
1619+
$blueprint = new Blueprint($this->getConnection(), 'users');
1620+
$blueprint->string('name', 100)->change()->instant();
1621+
$statements = $blueprint->toSql();
1622+
1623+
$this->assertCount(1, $statements);
1624+
$this->assertSame('alter table `users` modify `name` varchar(100) not null, algorithm=instant', $statements[0]);
1625+
}
1626+
16071627
public function getGrammar(?Connection $connection = null)
16081628
{
16091629
return new MySqlGrammar($connection ?? $this->getConnection());

0 commit comments

Comments
 (0)