Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add tinyText data type to Blueprint and to available database grammars #36949

Merged
merged 3 commits into from Apr 12, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
}
}