Skip to content

Loading…

DBAL-324: SchemaManager should first look into comment instead of infer the type first. #1509

Open
doctrinebot opened this Issue · 4 comments

3 participants

@doctrinebot

Jira issue originally created by user @guilhermeblanco:

When using schema tool, Doctrine tries to infer the Doctrine type via the mapped types in Platform.
It should first try to read from the comment; if found, ignore the Database type inference.

@doctrinebot

Comment created by @beberlei:

Why is this a bug? Can you say some more about why we need to do this and what error occurs?

@doctrinebot

Comment created by @guilhermeblanco:

This issue is strictly correlated to the commit I've done here: e25c774

Mainly, we may have legacy database that we do know how Doctrine should operate. Under this circumstance, we may want to add a comment to the field defining the Doctrine DBAL type.
Even though after doing this, Doctrine still complains (in my situation, a SET column type) that it's unable to handle this column type.

That happens because MySQL Schema Manager (and others) first looks for the column type:
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php#L112
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L312
which automatically fails.

But if we first try to look for the commented data type:
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php#L884
And forget about the rest if it finds one definition there, it would allow even unknown data types to be managed instead of forcing to define the DBAL Type compatible.

@doctrinebot

Comment created by steve@onzra.com:

This also applies for a type of yaml.
Example:

/*** @Column(type="yaml") **/
protected $data = array();

./scripts/doctrine orm:schema-tool:update --dump-sql
ALTER TABLE meta CHANGE data data LONGTEXT NOT NULL;

Very frustrating.... Might be related to http://www.doctrine-project.org/jira/browse/[DBAL-42](http://www.doctrine-project.org/jira/browse/DBAL-42)

@doctrinebot

Comment created by @deeky666:

[steve@onzra.com] You have defined a custom data type. You need to override Type::requiresSQLCommentHint() to return true in your custom data type, otherwise Doctrine cannot infer the custom type mapping from the column comment and the comparator will always detect changes between Yaml and LONGTEXT. This is not directly related to this issue here I think.
[
guiblanco] I don't really get the issue you describe here. Is it maybe fixed already? Otherwise can you maybe try to explain again so that I can fix that?

@doctrinebot doctrinebot added the Bug label
@deeky666 deeky666 self-assigned this
@deeky666 deeky666 added this to the 2.5.5 milestone
@deeky666 deeky666 added the WIP label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.