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

[10.x] Replace Deprecated DBAL Comparator creation with schema aware Comparator #46517

Merged
merged 10 commits into from
Mar 22, 2023

Conversation

liamh101
Copy link
Contributor

Reference to change in DBAL and why this needs to be done: doctrine/dbal#4746

This is currently causing this bug in Laravel where certain migration changes are ignored: #46492

Not sure if this is affecting other database types.

An example project of the existing bug can be found here: https://github.com/liamh101/laravel-column-bug

@liamh101
Copy link
Contributor Author

I'll get those failing integration tests fixed this evening, just need to pop out for a few hours.

@hafezdivandari
Copy link
Contributor

@liamh101 What about TableDiff on this function, do we have to replace that too?

public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
{
$table = $this->getTablePrefix().$blueprint->getTable();
return tap(new TableDiff($table), function ($tableDiff) use ($schema, $table) {
$tableDiff->fromTable = $schema->introspectTable($table);
});
}

@liamh101
Copy link
Contributor Author

@hafezdivandari Just need to do the introspectTable before creating the TableDiff class, and I believe the tap function call is now redundant. I'll get that changed and see if there are any side effects.

@hafezdivandari
Copy link
Contributor

@liamh101 isn't it better to change this function and use it on ChangeColumn class too if possible?

These are no longer included as provider in now schema aware when generating the SQL
@liamh101
Copy link
Contributor Author

@hafezdivandari can I do some further cleaning as a follow-up PR? I don't want to change too much and introduce additional bugs.

My feeling is that this bug can go under the radar on many projects and have massive consequences, partially multi-tenant projects where fresh database migrations can happen regularly.

@hafezdivandari
Copy link
Contributor

hafezdivandari commented Mar 19, 2023

@liamh101 sure, it was just a suggestion. But it seems that RenameColumn class has the same issue (using getDoctrineTableDiff()), I think we should not use TableDiff directly and use $schema->createComparator()->compareTables(). Does renaming a mediumText column using DBAL works right now?

@liamh101
Copy link
Contributor Author

Renaming a column will work. However, changing a text type using the default Comparator won't work.

Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging more into this @liamh101. I feel like we should give this a shot.

@taylorotwell
Copy link
Member

taylorotwell commented Mar 21, 2023

Can someone summarize all behavior changes / features / breaking changes / things we are not confident about for this PR in a single bullet point list? Please mark as ready for review when that is done.

@taylorotwell taylorotwell marked this pull request as draft March 21, 2023 12:00
@liamh101
Copy link
Contributor Author

Sure!

  • Replace deprecated DBAL Comparator creation for a Schema Aware Comparator. ( ChangeColumn.php) Reasoning why DBAL deprecated this can be found here: Platform-aware schema comparison  doctrine/dbal#4746
  • Clean up the additional deprecated function call to DBAL in Grammar.php however does not affect any behaviour.
  • Changes in DatabaseSchemaBlueprintIntegrationTest.php to account for SQL changes present between stable and lowest versions of DBAL 3.x .
  • Add schema builder test to validate text types change in MYSQL. The current version of Laravel is bugged with existing and new migrations. A project demonstrating this issue can be found here: https://github.com/liamh101/laravel-column-bug

No breaking changes were introduced in this PR, just a bug fix.

Once this has been reviewed and merged, I will investigate other places Laravel might use deprecated DBAL functionality and replace them. This PR is to fix the migration issues introduced when upgrading DBAL from 2.x to 3.x.

@liamh101 liamh101 marked this pull request as ready for review March 21, 2023 13:44
@taylorotwell taylorotwell merged commit f5f91ae into laravel:10.x Mar 22, 2023
@taylorotwell
Copy link
Member

Thanks

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

Successfully merging this pull request may close these issues.

4 participants