diff --git a/CHANGELOG.md b/CHANGELOG.md index 486381b..8c7f9f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 2e7e31d..8017253 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -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'; @@ -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') . '"'; } /** @@ -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()) . '"'; } /** diff --git a/tests/Schema/BlueprintTest.php b/tests/Schema/BlueprintTest.php index 338e8c7..f0aff91 100644 --- a/tests/Schema/BlueprintTest.php +++ b/tests/Schema/BlueprintTest.php @@ -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 @@ -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 not null default ([1, 2])', '`bool_array` array not null default ([false, true])', '`float_array` array not null default ([2.2, 3.3])', '`string_array` array not null default (["a", "b"])', - '`date_array` array not null default ([DATE "2022-01-01"])', - '`timestamp_array` array not null default ([TIMESTAMP "2022-01-01T00:00:00.000000+00:00"])', + '`date_array` array not null default ([date "2022-01-01"])', + '`timestamp_array` array not null default ([timestamp "2022-01-01T00:00:00.000000+00:00"])', ]) . ') primary key (`id`)', ], $statements); diff --git a/tests/TestCase.php b/tests/TestCase.php index 64f1434..7bb4434 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; @@ -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,