Skip to content

Commit

Permalink
feature: add Schema\Grammar::typeDouble for better compatibility (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomohito YABU <tyabu1212@gmail.com>
  • Loading branch information
taka-oyama and tyabu12 committed May 1, 2023
1 parent f4634b8 commit 4516732
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Added
- Added `Connection::runDdlBatch` which runs DDLs in batch synchronously. (#86)
- Added emulator support for `Connection::listSessions`. (#88)
- Added `Schema\Grammar::typeDouble` for better compatibility. (#97)

Fixed
- Fixed bug where running `Connection::statement` with DDLs was not logging and was not triggering events. (#86)
Expand Down
13 changes: 12 additions & 1 deletion src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ protected function typeBigInteger(Fluent $column)
*/
protected function typeInteger(Fluent $column)
{
return 'int64';
return $this->typeBigInteger($column);
}

/**
Expand All @@ -392,6 +392,17 @@ protected function typeInteger(Fluent $column)
* @return string
*/
protected function typeFloat(Fluent $column)
{
return $this->typeDouble($column);
}

/**
* Create the column definition for a double type.
*
* @param Fluent<string, mixed> $column
* @return string
*/
protected function typeDouble(Fluent $column)
{
return 'float64';
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ public function test_default_values(): void
$table->uuid('id');
$table->integer('null')->default(null)->nullable();
$table->integer('int')->default(1);
$table->bigInteger('bigint')->default(1);
$table->float('float')->default(0.1);
$table->double('double')->default(0.1);
$table->boolean('bool')->default(true);
$table->string('string')->default('a');
$table->text('string_max')->default('a');
Expand All @@ -367,6 +369,7 @@ public function test_default_values(): void
$table->dateTime('time_as_string')->default('2022-01-01');
$table->dateTime('time_as_carbon')->default(new Carbon('2022-01-01'));
$table->dateTime('current_time')->useCurrent();
$table->timestamp('current_time_as_ts')->useCurrent();
$table->integerArray('int_array')->default([1, 2]);
$table->booleanArray('bool_array')->default([false, true]);
$table->floatArray('float_array')->default([2.2, 3.3]);
Expand All @@ -385,7 +388,9 @@ public function test_default_values(): void
'`id` string(36) not null',
'`null` int64',
'`int` int64 not null default (1)',
'`bigint` int64 not null default (1)',
'`float` float64 not null default (0.1)',
'`double` 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")',
Expand All @@ -395,6 +400,7 @@ public function test_default_values(): void
'`time_as_string` timestamp not null default (TIMESTAMP "2022-01-01T00:00:00.000000+00:00")',
'`time_as_carbon` timestamp not null default (TIMESTAMP "2022-01-01T00:00:00.000000+00:00")',
'`current_time` timestamp not null default (CURRENT_TIMESTAMP())',
'`current_time_as_ts` timestamp not null default (CURRENT_TIMESTAMP())',
'`int_array` array<int64> not null default ([1, 2])',
'`bool_array` array<bool> not null default ([false, true])',
'`float_array` array<float64> not null default ([2.2, 3.3])',
Expand Down

0 comments on commit 4516732

Please sign in to comment.