-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Custom datetime with support of microseconds not properly works after update of dbal from 3.6 to 4.2.1 #6631
Comments
Started debugging and I can see that
new schema
so for some reason, Column diff sees the column in DB as type NOTE: I have custom type registered like this:
and in entity XML mapping
So for some reason after the update of DBAL, during the read of the current schema state doctrine transformed the existing timestamp(6) field into an incorrect type which is |
This is a known problem. DBAL does not support changing the precision of datetime fields. This is a planned feature and attempts have been made to contribute this, but so far nobody has brought it over the finish line. If you need a custom type for your datetime fields, you will have to override the comparator to enable it to detect the case that your custom type covers. However, if you want this behavior for every datetime field in your application, you might be better off overriding the platform instead. |
I do not think the issue is with my custom type, I tried with the original
and
So for some reason comparison now not use Doctrine comments like |
so if I understand it correctly it always generates migration because it sees that type in DB is |
Okay, but it is.
I'm not sure what I should be reading from these dumps, but if it's about a different type being found during introspection, this is usually fine if both types generate the same DDL.
The reason is that the support for those comments has been removed. You might want to read doctrine/migrations#1441 for issues with custom types following that removal. |
I just mentioned that I removed my custom type, and still doctrine generating all the time SQL but now of course |
Can you provide a minimal piece of code that proproduces your issue? |
Entity (I'll skip all other fields)
mapping (same, skipping all fields)
at a point of migration from DBAL 3.6+ to 4.2.1 I had custom type registered, initial migration looked like this
Now I have updated to DBAL 4.2.1 and as mentioned above, also removed custom type, mapping, and entity are the same (only change is removing the custom type which I'll not describe here), running
I run it and run
|
@bogdan-dubyk $this->addSql('CREATE TABLE audit_logs (
"id" UUID NOT NULL,
"date" TIMESTAMP(6) WITH TIME ZONE DEFAULT NULL,
PRIMARY KEY(id))');
$this->addSql('COMMENT ON COLUMN audit_logs.date IS \'(DC2Type:datetimetz_immutable)\''); #[ORM\Table(name: "audit_logs")]
#[ORM\Entity]
class AuditLog
{
#[ORM\Column(name: "date", type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
private \DateTimeImmutable $date;
} diff public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE audit_logs ALTER date TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('COMMENT ON COLUMN audit_logs.date IS \'\'');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE audit_logs ALTER date TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('COMMENT ON COLUMN audit_logs.date IS \'(DC2Type:datetimetz_immutable)\'');
} After
|
Maybe, still did not solve that, simply editing migrations all the time, no time to debug. But I also found another issue, here is the fresh version fo custom type
and issue is that This leads to an issue that UOW sees changes all the time. In example
will show changes like this
even if there are no actual changes, and I assume it's because |
I tried to add dumps to other default types |
Bug Report
Summary
I have a custom type to support microsecond precision with Postgres
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 migrationbut 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 migrationdown
section is generatingALTER 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 setExpected 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 versionThe text was updated successfully, but these errors were encountered: