Navigation Menu

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

Column altering in migration may not apply #12363

Closed
hovsep opened this issue Feb 18, 2016 · 3 comments
Closed

Column altering in migration may not apply #12363

hovsep opened this issue Feb 18, 2016 · 3 comments

Comments

@hovsep
Copy link

hovsep commented Feb 18, 2016

I have a text column called "body" . Then I want to alter it to be longText, so I run a migration with

$table->longText('body')->change(); (of course I have doctrine/dbal in my composer.json)

So migration runs ok, but actually no modification occurs.

I make some investigation and found that Laravel uses Doctrine\DBAL\Schema\Comparator class to make diffTable. Ok, sounds good, but how it compares columns? I debugged column properties at diffColumn method and see that my "longText" become to Doctrine\DBAL\Types\TextType.

So Doctrine makes no difference between Text and LongText. It is not ok.

@EliasZ
Copy link
Contributor

EliasZ commented Feb 19, 2016

Doctrine can make a difference between the various text sizes. See mapping matrix.

For example. LONGTEXT will be used if

column length is less or equal to 2 ^ 32 - 1 = 4294967295 or empty

If your issue is valid, there must be something wrong with calculateDoctrineTextLength. Maybe you can try and validate that.

@hovsep
Copy link
Author

hovsep commented Feb 19, 2016

I investigated deeper and found a problem in vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php _getPortableTableColumnDefinition method.

For example I create a migration with single mutation ($table->text('body')->change();)

So i debug $tableColumn var at beginning of the method :

Array ( [Field] => body [Type] => longtext [Null] => NO [Key] => [Default] => [Extra] => [Comment] => [CharacterSet] => utf8 [Collation] => utf8_unicode_ci )

Then I debug result :
`Doctrine\DBAL\Schema\Column Object
(
[_type:protected] => Doctrine\DBAL\Types\TextType Object
(
)

[_length:protected] => 
[_precision:protected] => 10
[_scale:protected] => 0
[_unsigned:protected] => 
[_fixed:protected] => 
[_notnull:protected] => 1
[_default:protected] => 
[_autoincrement:protected] => 
[_platformOptions:protected] => Array
    (
        [collation] => utf8_unicode_ci
    )

[_columnDefinition:protected] => 
[_comment:protected] => 
[_customSchemaOptions:protected] => Array
    (
    )

[_name:protected] => body
[_namespace:protected] => 
[_quoted:protected] => 

)
`

As you can see original longtext became a portable text type. So table diff will not be detected. I think such a behaviour may be useful when same code should work with different databases, but it is bug when we make a migration.

@EliasZ
Copy link
Contributor

EliasZ commented Feb 19, 2016

You should file your findings over at https://github.com/doctrine/dbal/issues/new 😃

This isn't an issue with Laravel. Laravel uses doctrine/dbal for certain database mutations.

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

3 participants