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
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,18 @@ public function rememberToken()
return $this->string('remember_token', 100)->nullable();
}

/**
* Create a new custom column on the table.
*
* @param string $column
* @param string $definition
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function rawColumn($column, $definition)
{
return $this->addColumn('raw', $column, compact('definition'));
}

/**
* Add a comment to the table.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ protected function typeVector(Fluent $column)
throw new RuntimeException('This database driver does not support the vector type.');
}

/**
* Create the column definition for a raw column type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeRaw(Fluent $column)
{
return $column->offsetGet('definition');
}

/**
* Add the column modifiers to the definition.
*
Expand Down
30 changes: 30 additions & 0 deletions tests/Database/DatabaseSchemaBlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,36 @@ public function testTinyTextNullableColumn()
], $blueprint->toSql($connection, new SqlServerGrammar));
}

public function testRawColumn()
{
$base = new Blueprint('posts', function ($table) {
$table->rawColumn('legacy_boolean', 'INT(1)')->nullable();
});

$connection = m::mock(Connection::class);

$blueprint = clone $base;
$this->assertEquals([
'alter table `posts` add `legacy_boolean` INT(1) null',
], $blueprint->toSql($connection, new MySqlGrammar));

$blueprint = clone $base;
$connection->shouldReceive('getServerVersion')->andReturn('3.35');
$this->assertEquals([
'alter table "posts" add column "legacy_boolean" INT(1)',
], $blueprint->toSql($connection, new SQLiteGrammar));

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add column "legacy_boolean" INT(1) null',
], $blueprint->toSql($connection, new PostgresGrammar));

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add "legacy_boolean" INT(1) null',
], $blueprint->toSql($connection, new SqlServerGrammar));
}

public function testTableComment()
{
$base = new Blueprint('posts', function (Blueprint $table) {
Expand Down