Skip to content

Commit b47e566

Browse files
committed
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.
1 parent 4117fec commit b47e566

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Configuration.php

+21
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class Configuration
5656
*/
5757
protected $autoCommit = true;
5858

59+
/**
60+
* Whether type comments should be disabled to provide the same DB schema than
61+
* will be obtained with DBAL 4.x. This is useful when relying only on the
62+
* platform-aware schema comparison (which does not need those type comments)
63+
* rather than the deprecated legacy tooling.
64+
*/
65+
private bool $disableTypeComments = false;
66+
5967
private ?SchemaManagerFactory $schemaManagerFactory = null;
6068

6169
public function __construct()
@@ -241,4 +249,17 @@ public function setSchemaManagerFactory(SchemaManagerFactory $schemaManagerFacto
241249

242250
return $this;
243251
}
252+
253+
public function getDisableTypeComments(): bool
254+
{
255+
return $this->disableTypeComments;
256+
}
257+
258+
/** @return $this */
259+
public function setDisableTypeComments(bool $disableTypeComments): self
260+
{
261+
$this->disableTypeComments = $disableTypeComments;
262+
263+
return $this;
264+
}
244265
}

src/Connection.php

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public function __construct(
209209

210210
$this->platform = $params['platform'];
211211
$this->platform->setEventManager($this->_eventManager);
212+
$this->platform->setDisableTypeComments($config->getDisableTypeComments());
212213
}
213214

214215
$this->_expr = $this->createExpressionBuilder();
@@ -315,6 +316,7 @@ public function getDatabasePlatform()
315316
if ($this->platform === null) {
316317
$this->platform = $this->detectDatabasePlatform();
317318
$this->platform->setEventManager($this->_eventManager);
319+
$this->platform->setDisableTypeComments($this->_config->getDisableTypeComments());
318320
}
319321

320322
return $this->platform;

src/Platforms/AbstractPlatform.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ abstract class AbstractPlatform
103103
*/
104104
protected $_keywords;
105105

106+
private bool $disableTypeComments = false;
107+
108+
/**
109+
* @internal
110+
*/
111+
final public function setDisableTypeComments(bool $value): void
112+
{
113+
$this->disableTypeComments = $value;
114+
}
115+
106116
/**
107117
* Sets the EventManager used by the Platform.
108118
*
@@ -578,7 +588,7 @@ protected function getColumnComment(Column $column)
578588

579589
$comment = $column->getComment();
580590

581-
if ($column->getType()->requiresSQLCommentHint($this)) {
591+
if (!$this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) {
582592
$comment .= $this->getDoctrineTypeComment($column->getType());
583593
}
584594

0 commit comments

Comments
 (0)