Skip to content

Commit

Permalink
[8.x] Add tinyText data type to Blueprint and to available database g…
Browse files Browse the repository at this point in the history
…rammars (#36949)

* Add tinyText to available grammars

* Update test to also check that nullable() also works on the new type

* Update style
  • Loading branch information
bennett-treptow committed Apr 12, 2021
1 parent ef99cff commit d834187
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Expand Up @@ -677,6 +677,17 @@ public function string($column, $length = null)
return $this->addColumn('string', $column, compact('length'));
}

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

/**
* Create a new text column on the table.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Expand Up @@ -490,6 +490,17 @@ protected function typeString(Fluent $column)
return "varchar({$column->length})";
}

/**
* Create the column definition for a tiny text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyText(Fluent $column)
{
return 'tinytext';
}

/**
* Create the column definition for a text type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Expand Up @@ -472,6 +472,17 @@ protected function typeString(Fluent $column)
return "varchar({$column->length})";
}

/**
* Create the column definition for a tiny text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyText(Fluent $column)
{
return 'varchar(255)';
}

/**
* Create the column definition for a text type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
Expand Up @@ -432,6 +432,17 @@ protected function typeString(Fluent $column)
return 'varchar';
}

/**
* Create the column definition for a tiny text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyText(Fluent $column)
{
return 'text';
}

/**
* Create the column definition for a text type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Expand Up @@ -417,6 +417,17 @@ protected function typeString(Fluent $column)
return "nvarchar({$column->length})";
}

/**
* Create the column definition for a tiny text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyText(Fluent $column)
{
return 'nvarchar(255)';
}

/**
* Create the column definition for a text type.
*
Expand Down
58 changes: 58 additions & 0 deletions tests/Database/DatabaseSchemaBlueprintTest.php
Expand Up @@ -291,4 +291,62 @@ public function testGenerateRelationshipColumnWithUuidModel()
'alter table `posts` add `eloquent_model_uuid_stub_id` char(36) not null',
], $blueprint->toSql($connection, new MySqlGrammar));
}

public function testTinyTextColumn()
{
$base = new Blueprint('posts', function ($table) {
$table->tinyText('note');
});

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

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

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add column "note" text not null',
], $blueprint->toSql($connection, new SQLiteGrammar));

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add column "note" varchar(255) not null',
], $blueprint->toSql($connection, new PostgresGrammar));

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add "note" nvarchar(255) not null',
], $blueprint->toSql($connection, new SqlServerGrammar));
}

public function testTinyTextNullableColumn()
{
$base = new Blueprint('posts', function ($table) {
$table->tinyText('note')->nullable();
});

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

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

$blueprint = clone $base;
$this->assertEquals([
'alter table "posts" add column "note" text',
], $blueprint->toSql($connection, new SQLiteGrammar));

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

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

0 comments on commit d834187

Please sign in to comment.