From b47e56630115989b855447dc231fd390d95ba49f Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 13 Sep 2023 19:58:07 +0200 Subject: [PATCH] Add a configuration setting to disable generating type comments This allows to opt-in for a schema generated without type comments once the project is migrating to the new schema tooling that does not need them, allowing to have a clean DB schema without waiting for DBAL 4.0 and to decouple the schema migration from the DBAL upgrade itself. --- src/Configuration.php | 21 +++++++++++++++++++++ src/Connection.php | 2 ++ src/Platforms/AbstractPlatform.php | 12 +++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index 8d8c8ee2d64..5cdae81354d 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -56,6 +56,14 @@ class Configuration */ protected $autoCommit = true; + /** + * Whether type comments should be disabled to provide the same DB schema than + * will be obtained with DBAL 4.x. This is useful when relying only on the + * platform-aware schema comparison (which does not need those type comments) + * rather than the deprecated legacy tooling. + */ + private bool $disableTypeComments = false; + private ?SchemaManagerFactory $schemaManagerFactory = null; public function __construct() @@ -241,4 +249,17 @@ public function setSchemaManagerFactory(SchemaManagerFactory $schemaManagerFacto return $this; } + + public function getDisableTypeComments(): bool + { + return $this->disableTypeComments; + } + + /** @return $this */ + public function setDisableTypeComments(bool $disableTypeComments): self + { + $this->disableTypeComments = $disableTypeComments; + + return $this; + } } diff --git a/src/Connection.php b/src/Connection.php index 1e79c9ea355..d84dc31586c 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -209,6 +209,7 @@ public function __construct( $this->platform = $params['platform']; $this->platform->setEventManager($this->_eventManager); + $this->platform->setDisableTypeComments($config->getDisableTypeComments()); } $this->_expr = $this->createExpressionBuilder(); @@ -315,6 +316,7 @@ public function getDatabasePlatform() if ($this->platform === null) { $this->platform = $this->detectDatabasePlatform(); $this->platform->setEventManager($this->_eventManager); + $this->platform->setDisableTypeComments($this->_config->getDisableTypeComments()); } return $this->platform; diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 033e952e24a..06297bfff3f 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -103,6 +103,16 @@ abstract class AbstractPlatform */ protected $_keywords; + private bool $disableTypeComments = false; + + /** + * @internal + */ + final public function setDisableTypeComments(bool $value): void + { + $this->disableTypeComments = $value; + } + /** * Sets the EventManager used by the Platform. * @@ -578,7 +588,7 @@ protected function getColumnComment(Column $column) $comment = $column->getComment(); - if ($column->getType()->requiresSQLCommentHint($this)) { + if (!$this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) { $comment .= $this->getDoctrineTypeComment($column->getType()); }