doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.65k stars 387 forks source link

Diff command generating unnecessary migration #1434

Closed KevinMarques closed 3 weeks ago

KevinMarques commented 3 weeks ago

Bug Report

Q A
BC Break no
Version 3.7.4
ORM 3.2.0
DBAL 4.0.3

Summary

When executing doctrine-migrations diff command, it generates a migration even though the entity and the database correspond to each other on datetime_immutable defined field.

Current behavior

Diff command generates unnecessary migration over and over again when already in sync: $this->addSql('ALTER TABLE test_entity ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');

If I change the entity column type to 'datetime' instead of 'datetime_immutable' then it works properly, but I need to use the immutable type.

How to reproduce

Entity definition:

#[ORM\Entity]
#[ORM\Table(name: 'test_entity')]
class TestEntity
{
    #[ORM\Column(name: 'created_at', type: 'datetime_immutable')]
    private DateTimeImmutable $createdAt;
}

Execute:

  1. doctrine-migrations diff
  2. doctrine-migrations migrate
  3. doctrine-migrations diff

Expected behavior

No migration generated when already in sync using the datetime_immutable type column.

KevinMarques commented 3 weeks ago

For others experiencing this problem, the solution is to first apply: COMMENT ON COLUMN test_entity.created_at IS ''.

These comments were removed in DBAL 4 and were causing the issue.