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

Add a configuration setting to disable generating type comments #6150

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
$this->disableTypeComments = $disableTypeComments;

return $this;
}
}
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