Skip to content

Commit

Permalink
Add a configuration setting to disable generating type comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stof committed Sep 13, 2023
1 parent 4117fec commit 384e889
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Check warning on line 259 in src/Configuration.php

View check run for this annotation

Codecov / codecov/patch

src/Configuration.php#L259

Added line #L259 was not covered by tests
{
$this->disableTypeComments = $disableTypeComments;

Check warning on line 261 in src/Configuration.php

View check run for this annotation

Codecov / codecov/patch

src/Configuration.php#L261

Added line #L261 was not covered by tests

return $this;

Check warning on line 263 in src/Configuration.php

View check run for this annotation

Codecov / codecov/patch

src/Configuration.php#L263

Added line #L263 was not covered by tests
}
}
2 changes: 2 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ 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.
*
Expand Down Expand Up @@ -578,7 +586,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());
}

Expand Down

0 comments on commit 384e889

Please sign in to comment.