diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index 28dc472cf252..1781185e9017 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -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. * diff --git a/src/Illuminate/Database/Schema/Grammars/Grammar.php b/src/Illuminate/Database/Schema/Grammars/Grammar.php index 12a4b367146a..b21fcf23b65d 100755 --- a/src/Illuminate/Database/Schema/Grammars/Grammar.php +++ b/src/Illuminate/Database/Schema/Grammars/Grammar.php @@ -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. * diff --git a/tests/Database/DatabaseSchemaBlueprintTest.php b/tests/Database/DatabaseSchemaBlueprintTest.php index b9048e2a2bed..1565ebc9c897 100755 --- a/tests/Database/DatabaseSchemaBlueprintTest.php +++ b/tests/Database/DatabaseSchemaBlueprintTest.php @@ -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) {