dbal: Validation schema failure after disabling DC2Type generation in Doctrine

Hello,

I have some issues. According to this https://github.com/doctrine/DoctrineBundle/pull/1714, it is possible to disable DC2Type generation. However, after enabling it, it is no longer possible to pass doctrine:schema:validate for the database. And it doesn’t even work for date*_immutable types.

Here is an example of my code. Initial migration:

$this->addSql('CREATE TABLE tbl (
			id                    UUID NOT NULL,
			recorded_at           TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
			PRIMARY KEY (id))');
//$this->addSql('COMMENT ON COLUMN tbl.id IS \'(DC2Type:tbl_id)\'');
//$this->addSql('COMMENT ON COLUMN tbl.recorded_at IS \'(DC2Type:datetime_immutable)\'');

Configuration:

doctrine:
    dbal:
        disable_type_comments: true

Entity:

#[ORM\Entity]
class AuditLog
{
    #[ORM\Column(name: 'id', type: 'tbl_id', nullable: false)]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private Id $id;

    #[ORM\Column(name: 'recorded_at', type: 'datetime_immutable', nullable: false, options: ['default' => 'now()'])]
    private \DateTimeImmutable $date;
	
}

When I run doctrine:schema:validate -v, I get the following output expecting DC2Type.

Mapping
-------

                                                                                                                        
 [OK] The mapping files are correct.                                                                                    
                                                                                                                        

Database
--------

                                                                                                                        
 [ERROR] The database schema is not in sync with the current mapping file.                                              
                                                                                                                        

 // 2 schema diff(s) detected:                                                                                          

     ALTER TABLE tbl ALTER id TYPE UUID;
     ALTER TABLE tbl ALTER recorded_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE;
     

Am I doing something wrong, or am I misunderstanding something, or is this a bug?

Thanks.

doctrine/cache                      2.2.0   PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                2.2.2   PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     3.4.4   PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxies and much more.
doctrine/data-fixtures              1.7.0   Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       3.8.4   Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               1.1.3   A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/doctrine-bundle            2.12.0  Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle   3.6.1   Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.3.1   Symfony DoctrineMigrationsBundle
doctrine/event-manager              2.0.1   The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  2.0.10  PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               2.0.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      3.0.1   PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.7.4   PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it...  
doctrine/orm                        2.19.5  Object-Relational-Mapper for PHP
doctrine/persistence                3.3.2   The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.4.0   a PHP SQL highlighting library

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

Alright, I’ll give it a try. It doesn’t seem too difficult.

Yeah it pass correctly column declaration SQL here: https://github.com/doctrine/dbal/blob/080aab5a9588f137ef3e1ad7e0d056a4517b4e16/src/Platforms/AbstractPlatform.php#L4676-L4678

But this line ruins everything: https://github.com/doctrine/dbal/blob/080aab5a9588f137ef3e1ad7e0d056a4517b4e16/src/Platforms/AbstractPlatform.php#L4696

I suppose there should be:

if($this->disableTypeComments){
            return true;
}        
return $column1->getType() === $column2->getType();

UPD: This check seems to solve the problem.

That’s diffColumn, I was asking for diffColumns.

EDIT: my bad, I should have asked for diffColumn 😅

The goal of the filter is to remove tables not managed by Doctrine, or the migrations table which is a special case.