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

Improve MySQL charset and collation comparison #5523

Merged
merged 1 commit into from Jul 22, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented Jul 20, 2022

Closes #5338.

This is an improvement of the logic implemented in #5471. Up until this patch, the comparator didn't work correctly if the column definition contained some options that would eventually match the table options but the table options weren't explicitly specified (i.e. they defaulted to the database defaults).

In order to address the issue, we need to normalize the table and column definitions and make all the default options explicit. Then compare the normalized definitions.

Backporting the fix to 3.x would require additional effort due to the MySQL platform there enforcing made-up defaults for table collation but not for column collation:

if (! isset($options['collation'])) {
$options['collation'] = $options['charset'] . '_unicode_ci';
}

In order to support this logic, we'd need to use two implementations of the charset metadata provider: one for columns that would detect the default charset based on the information schema; and one for tables that mimicks the behavior implemented in the platform.

@morozov morozov force-pushed the issues/4631 branch 3 times, most recently from 941005a to e70834d Compare July 20, 2022 02:46

self::assertContains(
'ALTER TABLE test_column_charset_change CHANGE col_string'
. ' col_string VARCHAR(100) CHARACTER SET ascii NOT NULL',
Copy link
Member Author

Choose a reason for hiding this comment

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

This patch affects the exact DDL used to alter the table: since now the column definition being compared always has an explicit charset and collation, it leaks into the resulting DDL (COLLATION ascii_general_ci is appended).

This is not a bug, since this is the default collation for the ascii charset according to the information schema.

Keeping this DDL unchanged would require additional juggling of column options. At the same time, a functional test shouldn't make assertions against SQL.

@morozov morozov linked an issue Jul 20, 2022 that may be closed by this pull request
@morozov morozov added this to the 4.0.0 milestone Jul 20, 2022
@morozov morozov marked this pull request as ready for review July 20, 2022 02:57
*/
final class CachingCharsetMetadataProvider implements CharsetMetadataProvider
{
private CharsetMetadataProvider $charsetMetadataProvider;
Copy link
Member

Choose a reason for hiding this comment

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

You can use constructor property promotion here and below (maybe also with the readonly keyword?)

Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 for CPP. 🙂

(maybe also with the readonly keyword?)

We would need to bump to PHP 8.1 for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be nice to enforce constructor property promotion in the coding standard. Otherwise, all code merged up from older branches will remain not using this syntax.

Copy link
Member

Choose a reason for hiding this comment

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

@morozov morozov merged commit 731e60e into doctrine:4.0.x Jul 22, 2022
@morozov morozov deleted the issues/4631 branch July 22, 2022 16:14
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema validation error (and diff error) when collation is set
3 participants