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 b47e566
Show file tree
Hide file tree
Showing 3 changed files with 34 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
12 changes: 11 additions & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ abstract class AbstractPlatform
*/
protected $_keywords;

private bool $disableTypeComments = false;

/**

Check failure on line 108 in src/Platforms/AbstractPlatform.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @internal
*/
final public function setDisableTypeComments(bool $value): void
{
$this->disableTypeComments = $value;
}

/**
* Sets the EventManager used by the Platform.
*
Expand Down Expand Up @@ -578,7 +588,7 @@ protected function getColumnComment(Column $column)

$comment = $column->getComment();

if ($column->getType()->requiresSQLCommentHint($this)) {
if (!$this->disableTypeComments && $column->getType()->requiresSQLCommentHint($this)) {

Check failure on line 591 in src/Platforms/AbstractPlatform.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Expected 1 space(s) after NOT operator; 0 found
$comment .= $this->getDoctrineTypeComment($column->getType());
}

Expand Down

0 comments on commit b47e566

Please sign in to comment.