Description
Bug Report
Q | A |
---|---|
Version | 4.2.1 |
Previous Version if the bug is a regression | 3.6 |
Summary
I have a custom type to support microsecond precision with Postgres
final class DateTimeImmutableMicrosecondsType extends VarDateTimeImmutableType
{
private const FORMAT = 'Y-m-d H:i:s.u';
/**
* @param T $value
*
* @return (T is null ? null : string)
*
* @throws ConversionException
*
* @template T
*/
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
if (
$value instanceof DateTimeImmutable &&
$platform instanceof PostgreSQLPlatform
) {
return $value->format(self::FORMAT);
}
return parent::convertToDatabaseValue($value, $platform);
}
/** @param mixed[] $column */
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if ($platform instanceof PostgreSQLPlatform) {
return 'TIMESTAMP(6) WITH TIME ZONE';
}
return $platform->getDateTimeTzTypeDeclarationSQL($column);
}
}
all was good on version 3.6, doctrine migration generated the SQL like updated_at TIMESTAMP(6) WITH TIME ZONE
and custom doctrine comments added 'COMMENT ON COLUMN products_data_api_schema.product.updated_at IS \'(DC2Type:datetime_immutable)\''
, but now after I update a DBAL version to 4.2.1 and run migrations diff, I see doctrine trying to generate new migration
$this->addSql('ALTER TABLE public.table ALTER updated_at TYPE TIMESTAMP(6) WITH TIME ZONE');
$this->addSql('COMMENT ON COLUMN public.table.updated_at IS \'\'');
but type is already TIMESTAMP(6)
and even if I execute that migration, doctrine again generates the same migration, and what is more interesting in the migration down
section is generating ALTER TABLE public.table ALTER update_at TYPE TIMESTAMP(0) WITH TIME ZONE
trying to set precision to 0 for some reason.
Current behavior
Doctrine always trying to generate migration like TIMESTAMP(6
but that type is already set
Expected behavior
Doctrine should not generate any schema changes to that field
How to reproduce
You need to have a field with type TIMESTAMP(6) in our Postgres table, have that custom doctrine type from above, and be on dbal version 4.2.1 and run doctrine:migrations:diff
. Though I'm not sure, maybe it's an issue of the migrations library, but I'm on the most supported version which is 3.8.2 and did not change migration version, I only increase the dbal version