Skip to content

Commit

Permalink
fix: use lower case for methods and type casts (#182)
Browse files Browse the repository at this point in the history
* fix: use lower case for methods and type casts

* add changelog
  • Loading branch information
taka-oyama authored Feb 20, 2024
1 parent dfbed79 commit f9ff0a8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changed
- Trait `ManagesStaleReads` has been removed (which contained `cursorWithTimestampBound()` and `selectWithTimestampBound()`. Use `selectWithOptions()` instead). (#178)
- `Blueprint::interleave()` and `IndexDefinition::interleave()` now throw an error instead of a deprecation. (#178)
- `Connection::transaction()`'s `$attempts` argument's default value was changed from 10 to -1 (which is a magic number for default value which is 11) (#179)
- All upper case functions and casting `DATE` `TIMESTAMP` `CURRENT_TIMESTAMP()` has been changed to lower case for consistency. (#182)

Fixed
- `Schema\Grammar::compileAdd()` `Schema\Grammar::compileChange()` `Schema\Grammar::compileChange()` now create separate statements (#159)
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ protected function typeDateTime(Fluent $column)
protected function typeTimestamp(Fluent $column)
{
if ($column->useCurrent) {
$column->default(new Expression('CURRENT_TIMESTAMP()'));
$column->default(new Expression('current_timestamp()'));
}

return 'timestamp';
Expand Down Expand Up @@ -736,7 +736,7 @@ protected function formatDateValue(Fluent $column, mixed $value): string
if (is_string($value)) {
$value = Carbon::parse($value);
}
return 'DATE "' . $value->format('Y-m-d') . '"';
return 'date "' . $value->format('Y-m-d') . '"';
}

/**
Expand Down Expand Up @@ -794,7 +794,7 @@ protected function formatTimestampValue(Fluent $column, mixed $value): string
if (is_string($value)) {
$value = Carbon::parse($value);
}
return 'TIMESTAMP "' . $value->format($this->getDateFormat()) . '"';
return 'timestamp "' . $value->format($this->getDateFormat()) . '"';
}

/**
Expand Down
17 changes: 8 additions & 9 deletions tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use LogicException;
use Ramsey\Uuid\Uuid;

class BlueprintTest extends TestCase
Expand Down Expand Up @@ -442,18 +441,18 @@ public function test_default_values(): void
'`long_text` string(max) not null default ("a")',
'`raw` float64 not null default (1.1)',
'`json` json not null default (json "[1,2,3]")',
'`date_as_string` date not null default (DATE "2022-01-01")',
'`date_as_carbon` date not null default (DATE "2022-01-01")',
'`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())',
'`date_as_string` date not null default (date "2022-01-01")',
'`date_as_carbon` date not null default (date "2022-01-01")',
'`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])',
'`string_array` array<string(1)> not null default (["a", "b"])',
'`date_array` array<date> not null default ([DATE "2022-01-01"])',
'`timestamp_array` array<timestamp> not null default ([TIMESTAMP "2022-01-01T00:00:00.000000+00:00"])',
'`date_array` array<date> not null default ([date "2022-01-01"])',
'`timestamp_array` array<timestamp> not null default ([timestamp "2022-01-01T00:00:00.000000+00:00"])',
]) . ') primary key (`id`)',
], $statements);

Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Colopl\Spanner\Connection;
use Colopl\Spanner\Schema\Blueprint;
use Colopl\Spanner\SpannerServiceProvider;
use DateTimeImmutable;
use Google\Cloud\Spanner\Bytes;
use Google\Cloud\Spanner\Date;
use Google\Cloud\Spanner\Numeric;
Expand Down Expand Up @@ -85,9 +86,9 @@ protected function generateTestRow(): array
'nullableFloatTest' => null,
'numericTest' => new Numeric('123.456'),
'nullableNumericTest' => null,
'timestampTest' => new \DateTimeImmutable(),
'timestampTest' => new DateTimeImmutable(),
'nullableTimestampTest' => null,
'dateTest' => new Date(new \DateTimeImmutable()),
'dateTest' => new Date(new DateTimeImmutable()),
'nullableDateTest' => null,
'bytesTest' => new Bytes("\x00\x01\x02"),
'nullableBytesTest' => null,
Expand Down

0 comments on commit f9ff0a8

Please sign in to comment.