Skip to content

Commit

Permalink
feature: add support for Blueprint::text (#83)
Browse files Browse the repository at this point in the history
* feature: add support for `Blueprint::text`

* Update src/Schema/Grammar.php

Co-authored-by: Tomohito YABU <[email protected]>

---------

Co-authored-by: Tomohito YABU <[email protected]>
  • Loading branch information
taka-oyama and tyabu12 authored Mar 20, 2023
1 parent 12ab08f commit 2cf7cce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# v4.7.0 (Not released yet)

Added
- Support `Blueprint::text` (translates to `STRING(MAX)`).

Chore
- Removed `ramsey/uuid` from composer.json since laravel already includes it.

Expand Down
11 changes: 11 additions & 0 deletions src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ protected function typeString(Fluent $column)
return "string({$column->length})";
}

/**
* Create the column definition for a text type.
*
* @param Fluent<string, mixed> $column
* @return string
*/
protected function typeText(Fluent $column)
{
return "string(max)";
}

/**
* Create the column definition for a binary type.
*
Expand Down
14 changes: 13 additions & 1 deletion tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testCreateTable(): void
$table->integer('int');
$table->float('float');
$table->string('name');
$table->text('text');
$table->dateTime('started_at');
$table->binary('blob');
$table->timestamps();
Expand All @@ -47,7 +48,16 @@ public function testCreateTable(): void

$queries = $blueprint->toSql($conn, new Grammar());
$this->assertEquals(
'create table `Test3` (`id` string(36) not null, `int` int64 not null, `float` float64 not null, `name` string(255) not null, `started_at` timestamp not null, `blob` bytes(255) not null, `created_at` timestamp, `updated_at` timestamp) primary key (`id`)',
'create table `Test3` (' . implode(', ', [
'`id` string(36) not null',
'`int` int64 not null',
'`float` float64 not null',
'`name` string(255) not null',
'`text` string(max) not null',
'`started_at` timestamp not null',
'`blob` bytes(255) not null',
'`created_at` timestamp, `updated_at` timestamp',
]) . ') primary key (`id`)',
$queries[0]
);
}
Expand Down Expand Up @@ -336,6 +346,7 @@ public function test_default_values(): void
$table->float('float')->default(0.1);
$table->boolean('bool')->default(true);
$table->string('string')->default('a');
$table->text('string_max')->default('a');
$table->float('raw')->default(DB::raw('1.1'));
$table->date('date_as_string')->default('2022-01-01');
$table->date('date_as_carbon')->default(new Carbon('2022-01-01'));
Expand Down Expand Up @@ -363,6 +374,7 @@ public function test_default_values(): void
'`float` float64 not null default (0.1)',
'`bool` bool not null default (true)',
'`string` string(255) not null default ("a")',
'`string_max` string(max) not null default ("a")',
'`raw` float64 not null default (1.1)',
'`date_as_string` date not null default (DATE "2022-01-01")',
'`date_as_carbon` date not null default (DATE "2022-01-01")',
Expand Down

0 comments on commit 2cf7cce

Please sign in to comment.