doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.47k stars 1.34k forks source link

Invalid platform: PostgreSQL120Platform after upgrade to 3.9.0 #6506

Closed aprokopenko closed 2 months ago

aprokopenko commented 2 months ago

Bug Report

Q A
Version 3.9.0

Summary

After upgrade to 3.9.0 my migrations stop working (I'm using Laravel, which under the hood use your package). Create tables works fine, but all alters fail.

Current behaviour

After upgrade I have such error:

   Doctrine\DBAL\Exception 

  Invalid platform: PostgreSQL120Platform

  at vendor/laravel/framework/src/Illuminate/Database/DBAL/TimestampType.php:46
     42▕             PostgreSQL100Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
     43▕             SQLServerPlatform::class,
     44▕             SQLServer2012Platform::class => $this->getSqlServerPlatformSQLDeclaration($column),
     45▕             SqlitePlatform::class => 'DATETIME',
  ➜  46▕             default => throw new DBALException('Invalid platform: '.substr(strrchr(get_class($platform), '\\'),

Returning back to 3.8.7 works totally fine. I have PostgreSQL 16.1. The platform is detected now as PostgreSQL120Platform, but it doesn't added everywhere inside the code, for example in TimestampType, the swtch looks like this and miss this class to identify sql declaration syntax:

    public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
    {
        return match (get_class($platform)) {
            MySQLPlatform::class,
            MySQL57Platform::class,
            MySQL80Platform::class,
            MariaDBPlatform::class,
            MariaDb1027Platform::class,
            MariaDb1052Platform::class,
            MariaDb1060Platform::class => $this->getMySqlPlatformSQLDeclaration($column),
            PostgreSQLPlatform::class,
            PostgreSQL94Platform::class,
            PostgreSQL100Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
            SQLServerPlatform::class,
            SQLServer2012Platform::class => $this->getSqlServerPlatformSQLDeclaration($column),
            SqlitePlatform::class => 'DATETIME',
            default => throw new DBALException('Invalid platform: '.substr(strrchr(get_class($platform), '\\'), 1)),
        };
    }

How to reproduce

Didn't created test project with clean Doctrine, but for me my migrations for create table works find and alter queries (for change default value for example of the column - fails)

Expected behaviour

No fatal errors in new releases :)

derrabus commented 2 months ago

Report this to Laravel, please.

aprokopenko commented 2 months ago

But TimestampType in your code really doesn't have case for new platform added and it generate a fatal error in case you try to use it.

greg0ire commented 2 months ago

Is TimestampType really in our code? Please provide a Github link to TimestampType. In general, please provide links to things you refer to.

aprokopenko commented 2 months ago

Sorry, maybe was a hard week, re-checked and this is really Laravel class.

greg0ire commented 2 months ago

No worries, have a nice end of week :)

derrabus commented 2 months ago

That match statement you quoted is brittle and will continue to break with new DBAL releases or if you dare to override the platform. But it's not our code, so we can't do much about it.

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.