doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.86k stars 2.5k forks source link

Add support for VARCHAR type with no length limit in PostgreSQL for ORM3 due to a bug in DBAL3 #11502

Closed berkut1 closed 5 days ago

berkut1 commented 1 week ago

Feature Request

Q A
New Feature yes
RFC yes/no
BC Break no

Summary

Hello!

When preparing to transition to DBAL4 and ORM3, I found a bug that has existed for a long time in DBAL3. The bug allows using VARCHAR without a length because when synchronizing schemas, the check for length = null for the string type will always return VARCHAR(255), even though in the database it will be VARCHAR. This is because the function does not know how to return VARCHAR https://github.com/doctrine/dbal/blob/0e3536ba088a749985c8801105b6b3ac6c1280b6/src/Platforms/PostgreSQLPlatform.php#L1129-L1133

Therefore, VARCHAR will always equal VARCHAR(255) in DBAL3. However, DBAL4 can correctly determine the database schema and return VARCHAR (https://github.com/doctrine/dbal/blob/8edbce73bc1aa2251ba8c754fc440f8e02c661bc/src/Platforms/PostgreSQLPlatform.php#L637), which breaks all unlimited VARCHAR types in ORM3 that DBAL3 allowed through due to the bug.

A possible solution would be to allow ORM3 to use VARCHAR if length = null by removing the null check https://github.com/doctrine/orm/blob/9d4f54b9a476f13479c3845350b12c466873fc42/src/Tools/SchemaTool.php#L463-L465 if PostgreSQL (and possibly other platforms like SQLite?) is being used.

Thanks!