Skip to content

Reference base platform class in generated platform check - #1595

Open
maks-oleksyuk wants to merge 1 commit into
doctrine:3.9.xfrom
maks-oleksyuk:fix/generator-use-base-platform-class
Open

maks-oleksyuk wants to merge 1 commit into
doctrine:3.9.xfrom
maks-oleksyuk:fix/generator-use-base-platform-class

Conversation

@maks-oleksyuk

Copy link
Copy Markdown
Q A
Type improvement
BC Break no
Fixed issues -

Summary

SqlGenerator emits an abortIf() guard into generated migrations using the exact class of the current platform (get_class($this->platform)). With DBAL 4 this is a version-specific subclass, e.g.:

$this->abortIf(
    !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MariaDB120300Platform,
    "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MariaDB120300Platform'."
);

These versioned platform classes are deprecated in DBAL (e.g. MariaDB120300Platform is marked @deprecated To be removed along with the keyword list feature). They only differ from their parents by the reserved keyword list, which DBAL deprecated in doctrine/dbal#6607 and made unnecessary in doctrine/dbal#6589 by always quoting identifiers.

As a result, every freshly generated migration hard-codes a deprecated class that will disappear in a future DBAL major version. The guard is also fragile: a migration generated on MariaDB 12.3 refuses to run on any other MariaDB version.

This PR makes the generator walk up to the topmost concrete platform class (MariaDBPlatform, MySQLPlatform, PostgreSQLPlatform, SQLitePlatform, ...), so the generated guard checks the database vendor only. Reflection is used instead of a hard-coded list so the declared class name casing is preserved (SqlitePlatform on DBAL 3, SQLitePlatform on DBAL 4) and custom platforms keep working.

Only the generated code changes. Existing migrations and runtime behaviour are not affected, and check_database_platform: false still disables the guard entirely.

A test covering a platform subclass is added; it fails without the change.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maks-oleksyuk
maks-oleksyuk force-pushed the fix/generator-use-base-platform-class branch from f17d6be to 4c3b61b Compare October 5, 2026 06:47
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.

1 participant