Skip to content
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

Incorrect detection of text[] type when generating migrations #217

Open
janklan opened this issue Jul 4, 2024 · 1 comment
Open

Incorrect detection of text[] type when generating migrations #217

janklan opened this issue Jul 4, 2024 · 1 comment

Comments

@janklan
Copy link

janklan commented Jul 4, 2024

I have issue similar to #71, but this time with text[] field:

#[ORM\Column(name: 'applicable_to', type: 'text[]', nullable: true, enumType: DomainEnum::class)]
protected ?array $applicableTo = null;

The up migration always contains:

$this->addSql('ALTER TABLE core.label ALTER applicable_to TYPE text[]');

And down migration:

$this->addSql('ALTER TABLE core.label ALTER applicable_to TYPE VARCHAR(255)');

The enumType (whether it's there or not) makes no difference.

Symfony config file (our app has all things related to this bundle in a separate file) looks like this:

doctrine:
    dbal:
        types:
            text[]: MartinGeorgiev\Doctrine\DBAL\Types\TextArray
            jsonb: MartinGeorgiev\Doctrine\DBAL\Types\Jsonb
            jsonb[]: MartinGeorgiev\Doctrine\DBAL\Types\JsonbArray
            
        connections:
            default:
                mapping_types:
                    text[]: text[]
                    _text: text[]
                    jsonb: jsonb
                    jsonb[]: jsonb[]
                    _jsonb: jsonb[]

    orm:
        entity_managers:
            default:
                dql:
                    string_functions:
                        # Bunch of functions enabled, but not all. Trimmed because I don't think it's relevant. Please correct me if I'm wrong.

Packages:

/srv/app $ composer info | grep doctrine
doctrine/annotations                       2.0.1              Docblock Annotations Parser
doctrine/cache                             2.2.0              PHP Doctrine Cache library is a popular cache implementation that supports many different driver...
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 Doctr...
doctrine/data-fixtures                     1.7.0              Data Fixtures for all Doctrine Object Managers
doctrine/dbal                              3.8.6              Powerful PHP database abstraction layer (DBAL) with many features for database schema introspect...
doctrine/deprecations                      1.1.3              A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disabl...
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 vario...
doctrine/inflector                         2.0.10             PHP Doctrine Inflector is a small library that can perform string manipulations with regard to u...
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.8.0              PHP Doctrine Migrations project offer additional functionality on top of the database abstractio...
doctrine/orm                               2.19.6             Object-Relational-Mapper for PHP
doctrine/persistence                       3.3.3              The Doctrine Persistence project is a set of shared interfaces and functionality that the differ...
doctrine/sql-formatter                     1.4.0              a PHP SQL highlighting library
martin-georgiev/postgresql-for-doctrine    2.5.0              Adds PostgreSQL enhancements to Doctrine. Provides support for JSON, JSONB and some array data t...

Please advise.

@stof
Copy link

stof commented Aug 14, 2024

This is because the TextArray type should override getMappedDatabaseTypes to properly associate the _text type (that's how text[] is reported during introspection) to this type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants