diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4d9555..a19be083 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # v8.3.0 (2024-09-02) +- add support for invisible columns (#240) - add support for change streams using Blueprint (#230) - add support for snapshot queries (#215) - deprecate Connection::getDatabaseContext() and move logic to UseMutations::getMutationExecutor() (#227) diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index c9fddd77..4b72442f 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -38,7 +38,7 @@ class Grammar extends BaseGrammar /** * @inheritdoc */ - protected $modifiers = ['Nullable', 'Default', 'UseSequence']; + protected $modifiers = ['Nullable', 'Default', 'Invisible', 'UseSequence']; /** * Compile the query to determine the tables. @@ -733,6 +733,20 @@ protected function typeBoolean(Fluent $column) return 'bool'; } + /** + * Get the SQL for an invisible column modifier. + * + * @param Blueprint $blueprint + * @param ColumnDefinition&object{ invisible: bool } $column + * @return string|null + */ + protected function modifyInvisible(Blueprint $blueprint, Fluent $column) + { + return $column->invisible !== null + ? ' hidden' + : null; + } + /** * @param Blueprint $blueprint * @param IntColumnDefinition $column diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index 666fd376..ff38d7cd 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -255,6 +255,30 @@ public function test_composite_primary_key(): void ], $statements); } + public function test_invisible_columns(): void + { + $conn = $this->getDefaultConnection(); + $grammar = new Grammar(); + $tableName = $this->generateTableName('Invisible'); + + $blueprint = new Blueprint($tableName, function (Blueprint $table) { + $table->create(); + $table->integer('id')->primary(); + $table->string('name')->nullable()->invisible(); + }); + + $this->assertSame([ + "create table `{$tableName}` (`id` int64 not null, `name` string(255) hidden) primary key (`id`)", + ], $blueprint->toSql($conn, $grammar)); + + $blueprint->build($conn, $grammar); + + $conn->table($tableName)->insert(['id' => 1, 'name' => 'test']); + $row = $conn->table($tableName)->first(); + $this->assertArrayHasKey('id', $row); + $this->assertArrayNotHasKey('name', $row); + } + public function test_interleaving(): void { $conn = $this->getDefaultConnection();