-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support precision option in datetime types (PostgreSQL) #6742
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,39 +6,15 @@ | |
|
|
||
| use DateTimeImmutable; | ||
| use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
| use Doctrine\DBAL\Types\Exception\InvalidType; | ||
| use Doctrine\DBAL\Types\Exception\ValueNotConvertible; | ||
| use Exception; | ||
|
|
||
| /** | ||
| * Immutable type of {@see VarDateTimeType}. | ||
| * @deprecated Use {@see DateTimeImmutableType} instead. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this relevant to introducing the support for precision? |
||
| */ | ||
| class VarDateTimeImmutableType extends DateTimeImmutableType | ||
| { | ||
| /** | ||
| * @param T $value | ||
| * | ||
| * @return (T is null ? null : string) | ||
| * | ||
| * @template T | ||
| */ | ||
| public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string | ||
| { | ||
| if ($value === null) { | ||
| return $value; | ||
| } | ||
|
|
||
| if ($value instanceof DateTimeImmutable) { | ||
| return $value->format($platform->getDateTimeFormatString()); | ||
| } | ||
|
|
||
| throw InvalidType::new( | ||
| $value, | ||
| static::class, | ||
| ['null', DateTimeImmutable::class], | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param T $value | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -649,6 +649,34 @@ public function testPartitionTable(): void | |
| )); | ||
| self::assertSame(1, $partitionsCount); | ||
| } | ||
|
|
||
| public function testTimestampPrecisionComparison(): void | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this to |
||
| { | ||
| $offlineTable = new Table('timestamp_columns_test'); | ||
| $offlineTable->addColumn('t_0_wz', Types::DATETIME_MUTABLE, ['precision' => 0]); | ||
| $offlineTable->addColumn('t_6_wz', Types::DATETIME_MUTABLE, ['precision' => 6]); | ||
| $offlineTable->addColumn('t_u_wz', Types::DATETIME_MUTABLE, ['precision' => 6]); | ||
| $offlineTable->addColumn('t_0_tz', Types::DATETIMETZ_MUTABLE, ['precision' => 0]); | ||
| $offlineTable->addColumn('t_6_tz', Types::DATETIMETZ_MUTABLE, ['precision' => 6]); | ||
| $offlineTable->addColumn('t_u_tz', Types::DATETIMETZ_MUTABLE, ['precision' => 6]); | ||
|
|
||
| $createTableSQL = <<<'SQL' | ||
| CREATE TABLE timestamp_columns_test ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why create this table via SQL if the table is already defined above via the DBAL API? |
||
| t_0_wz TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, | ||
| t_6_wz TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL, | ||
| t_u_wz TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
| t_0_tz TIMESTAMP(0) WITH TIME ZONE NOT NULL, | ||
| t_6_tz TIMESTAMP(6) WITH TIME ZONE NOT NULL, | ||
| t_u_tz TIMESTAMP WITH TIME ZONE NOT NULL | ||
| ) | ||
| SQL; | ||
|
|
||
| $this->connection->executeStatement($createTableSQL); | ||
|
|
||
| $onlineTable = $this->connection->createSchemaManager()->introspectTable($offlineTable->getName()); | ||
|
|
||
| self::assertEquals($offlineTable->getColumns(), $onlineTable->getColumns()); | ||
| } | ||
| } | ||
|
|
||
| class MoneyType extends Type | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see if this could be replaced with
$this->parseColumnTypeParameters($completeType)(introduced in #6933). You will need to rebase on4.3.xand retarget the PR.