Skip to content

Commit 2dd7eb8

Browse files
authored
Add a configuration setting to disable generating type comments (doctrine#6150)
| Q | A |------------- | ----------- | Type | feature | Fixed issues | closes doctrine#6056 #### Summary 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. I decided to name that field `disable*` so that the opt-in for the new behavior is done by setting it to `true`
1 parent 4117fec commit 2dd7eb8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-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

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

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

579587
$comment = $column->getComment();
580588

581-
if ($column->getType()->requiresSQLCommentHint($this)) {
589+
if (! $this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) {
582590
$comment .= $this->getDoctrineTypeComment($column->getType());
583591
}
584592

0 commit comments

Comments
 (0)