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

Create an easy way to extend the schema manager #5812

Closed
derrabus opened this issue Nov 7, 2022 · 10 comments
Closed

Create an easy way to extend the schema manager #5812

derrabus opened this issue Nov 7, 2022 · 10 comments

Comments

@derrabus
Copy link
Member

derrabus commented Nov 7, 2022

Feature Request

Q A
New Feature yes
RFC no

Summary

In #5784, the event system of the DBAL has been deprecated. One of the current use-cases is to modify the SQL emitted by the schema manager after a schema comparison. Instead, developers should extend the schema manager directly now. However, it is not really easy to do that at the moment because it involves overriding the driver as well.

My idea would be to allow a developer to pass a callable to DriverManager that constructs a schema manager instance and thus overrides the schema manager created by the driver/platform.

@derrabus derrabus added this to the 3.6.0 milestone Nov 7, 2022
@eugene-borovov
Copy link

Is it easy enough?

DriverManager::getConnection(
    [
        'driver' => ...
        'wrapperClass' => SchemaOverriddenConnection::class,
    ]
);

class SchemaOverriddenConnection extends Connection
{
  public function createSchemaManager(): AbstractSchemaManager
  {
     return new OverriddenSchemaManager($this, $this->getDatabasePlatform());
  }
}

@derrabus
Copy link
Member Author

derrabus commented Nov 7, 2022

Good one, but maybe we can manage to do that without providing our own wrapper class. It's possible for the driver and the platform, why shouldn't it be for the schema manager?

@eugene-borovov
Copy link

Driver is a factory for the Connection internals. Wrapper class allows override driver creational methods without exposing dependency in the constructor.

@derrabus
Copy link
Member Author

derrabus commented Nov 7, 2022

So, what you're saying is, extending the wrapper class is the way to go? In that case, this would be a pure documentation issue.

@eugene-borovov
Copy link

Another way is using \Doctrine\DBAL\Configuration for schema manager overriding like middleware configuration.

@eugene-borovov
Copy link

class \Doctrine\DBAL\Configuration
{
    
  // ....

  private ?AbstractSchemaManager $schemaManager = null;
  
  public function getSchemaManager(): ?AbstractSchemaManager
  {
    return $this->schemaManager;
  }  
  
  public function setSchemaManager(AbstractSchemaManager $schemaManager): void
  {
    $this->schemaManager = $schemaManager;
  }  
  
  // ....
	
}


class \Doctrine\DBAL\Connection
{
  // ...
  
  public function createSchemaManager(): AbstractSchemaManager
  {
    return $this->_config->getSchemaManager() ?? 
        $this->_driver->getSchemaManager($this, $this->getDatabasePlatform());
  }
  
  // ...

}

@eugene-borovov
Copy link

So, what you're saying is, extending the wrapper class is the way to go? In that case, this would be a pure documentation issue.

It looks like a more correct way to override schema manager is using \Doctrine\DBAL\Driver\Middleware. But it's not so easy anymore. Although technically it is also a wrapper class.

@frsmoray
Copy link

Would an implementation of a custom Schema manager like as in the suggested example (of an overridden schema manager as OverriddenSchemaManager) be able to let a developer place a table prefix as it can be done with current dbal deprecated event system?

@derrabus
Copy link
Member Author

I've worked on an implementation in #5876.

@derrabus derrabus removed this from the 3.6.0 milestone Jan 31, 2023
@github-actions
Copy link

github-actions bot commented Mar 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants