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

Deprecate not specifying charset #5278

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ awareness about deprecated code.

# Upgrade to 3.4

# Deprecated `AbstractPlatform` schema introspection methods
## Deprecated omitting the charset when using MySQL

Omitting the charset when using MySQL results in the deprecated `utf8` MySQL
charset being used. Configure it explicitly when creating a table:
```php
use Doctrine\DBAL\Schema\Table;

$table = new Table('a_table', [new Column('a_column', Type::getType('string'))]);
$table->addOption('charset', 'utf8mb4');
```

## Deprecated `AbstractPlatform` schema introspection methods

The following schema introspection methods have been deprecated:

Expand All @@ -19,22 +30,22 @@ The following schema introspection methods have been deprecated:

The queries used for schema introspection are an internal implementation detail of the DBAL.

# Deprecated `collate` option for MySQL
## Deprecated `collate` option for MySQL

This undocumented option is deprecated in favor of `collation`.

# Deprecated `AbstractPlatform::getListTableConstraintsSQL()`
## Deprecated `AbstractPlatform::getListTableConstraintsSQL()`

This method is unused by the DBAL since 2.0.

# Deprecated `Type::getName()`
## Deprecated `Type::getName()`

This will method is not useful for the DBAL anymore, and will be removed in 4.0.
As a consequence, depending on the name of a type being `json` for `jsonb` to
be used for the Postgres platform is deprecated in favor of extending
`Doctrine\DBAL\Types\JsonType`.

# Deprecated `AbstractPlatform::getColumnComment()` and `AbstractPlatform::getDoctrineTypeComment()`
## Deprecated `AbstractPlatform::getColumnComment()` and `AbstractPlatform::getDoctrineTypeComment()`

DBAL no longer needs column comments to ensure proper diffing. Note that both
methods should probably have been marked as internal as these comments were an
Expand Down
5 changes: 5 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ private function buildTableOptions(array $options): string

// Charset
if (! isset($options['charset'])) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5278',
'Omitting the charset option is deprecated, be explicit about it instead. We recommend using "utf8b4"'
);
$options['charset'] = 'utf8';
Copy link
Member Author

Choose a reason for hiding this comment

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

The charset and collation parameters are optional because they are not portable and are not required in the CREATE TABLE DDL.

@morozov ok, so although this is not the right way to handle the problem, you do admit there is an issue on this line, right? If the charset parameter is optional, why is there a default value here?

Copy link
Member

@morozov morozov Feb 15, 2022

Choose a reason for hiding this comment

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

you do admit there is an issue on this line, right?

Yes, it will be addressed by #4644.

If the charset parameter is optional, why is there a default value here?

I don't know. See #4644 (comment).

}

Expand Down
9 changes: 9 additions & 0 deletions tests/Platforms/MySQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use InvalidArgumentException;

Expand Down Expand Up @@ -54,4 +56,11 @@ public function testCollateOptionIsStillSupportedButDeprecated(): void
$this->platform->getCreateTableSQL($table)[0]
);
}

public function testOmittingTheCharsetIsDeprecated(): void
{
$table = new Table('a_table', [new Column('a_column', Type::getType('string'))]);
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5278');
$this->platform->getCreateTableSQL($table);
}
}