Skip to content

Commit

Permalink
[8.x] Add invisible modifier for MySQL columns (#40002)
Browse files Browse the repository at this point in the history
* add invisible modifier for MySQL columns.

* Update ColumnDefinition.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
lupinitylabs and taylorotwell authored Dec 13, 2021
1 parent fa7dd77 commit 6ffc63a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Illuminate/Database/Schema/ColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @method $this from(int $startingValue) Set the starting value of an auto-incrementing field (MySQL / PostgreSQL)
* @method $this generatedAs(string|Expression $expression = null) Create a SQL compliant identity column (PostgreSQL)
* @method $this index(string $indexName = null) Add an index
* @method $this invisible() Specify that the column should be invisible to "SELECT *" (MySQL)
* @method $this nullable(bool $value = true) Allow NULL values to be inserted into the column
* @method $this persisted() Mark the computed generated column as persistent (SQL Server)
* @method $this primary() Add a primary index
Expand Down
16 changes: 15 additions & 1 deletion src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MySqlGrammar extends Grammar
* @var string[]
*/
protected $modifiers = [
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable', 'Invisible',
'Srid', 'Default', 'Increment', 'Comment', 'After', 'First',
];

Expand Down Expand Up @@ -1038,6 +1038,20 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
}
}

/**
* Get the SQL for an invisible column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyInvisible(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->invisible)) {
return ' invisible';
}
}

/**
* Get the SQL for a default column modifier.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ public function testAddingGeneratedColumnWithCharset()
$this->assertSame('alter table `links` add `url` varchar(2083) character set ascii not null, add `url_hash_virtual` varchar(64) character set ascii as (sha2(url, 256)), add `url_hash_stored` varchar(64) character set ascii as (sha2(url, 256)) stored', $statements[0]);
}

public function testAddingInvisibleColumn()
{
$blueprint = new Blueprint('users');
$blueprint->string('secret', 64)->nullable(false)->invisible();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add `secret` varchar(64) not null invisible', $statements[0]);
}

public function testAddingString()
{
$blueprint = new Blueprint('users');
Expand Down

0 comments on commit 6ffc63a

Please sign in to comment.