Skip to content

Commit

Permalink
[11.x] Ignoring column definitions when determining if a blueprint ha…
Browse files Browse the repository at this point in the history
…s a create command (#52177)

* Added a test to ensure that a database column named 'create' can be added to an existing table

* Ignoring column definitions when determining if a blueprint has a create command

* Changes from StyleCI

* Update tests/Integration/Database/DatabaseSchemaBlueprintTest.php

Co-authored-by: Hafez Divandari <[email protected]>

* Update Blueprint.php

---------

Co-authored-by: Simon Geoghegan <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
Co-authored-by: Hafez Divandari <[email protected]>
  • Loading branch information
4 people authored Jul 18, 2024
1 parent 45592e6 commit 1883126
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function addAlterCommands(Connection $connection, Grammar $grammar)
public function creating()
{
return collect($this->commands)->contains(function ($command) {
return $command->name === 'create';
return ! $command instanceof ColumnDefinition && $command->name === 'create';
});
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/Database/DatabaseSchemaBlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,19 @@ public function testAddUniqueIndexWithNameWorks()
$this->assertEquals($expected, $queries);
}

public function testAddColumnNamedCreateWorks()
{
Schema::create('users', function (Blueprint $table) {
$table->string('name');
});

Schema::table('users', function (Blueprint $table) {
$table->string('create');
});

$this->assertTrue(Schema::hasColumn('users', 'create'));
}

public function testDropIndexOnColumnChangeWorks()
{
$connection = DB::connection();
Expand Down

0 comments on commit 1883126

Please sign in to comment.