Skip to content

Commit

Permalink
Add support for disabling type comments in the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Oct 23, 2023
1 parent d0e2a33 commit cae8e39
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->defaultValue(true)
->info('Enables collecting schema errors when profiling is enabled')
->end()
->booleanNode('disable_type_comments')->end()

Check warning on line 220 in DependencyInjection/Configuration.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/Configuration.php#L220

Added line #L220 was not covered by tests
->scalarNode('server_version')->end()
->scalarNode('driver_class')->end()
->scalarNode('wrapper_class')->end()
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder

unset($connection['auto_commit']);

if (isset($connection['disable_type_comments'])) {
$configuration->addMethodCall('setDisableTypeComments', [$connection['disable_type_comments']]);

Check warning on line 254 in DependencyInjection/DoctrineExtension.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/DoctrineExtension.php#L253-L254

Added lines #L253 - L254 were not covered by tests
}

unset($connection['disable_type_comments']);

Check warning on line 257 in DependencyInjection/DoctrineExtension.php

View check run for this annotation

Codecov / codecov/patch

DependencyInjection/DoctrineExtension.php#L257

Added line #L257 was not covered by tests

if (isset($connection['schema_filter']) && $connection['schema_filter']) {
$definition = new Definition(RegexSchemaAssetFilter::class, [$connection['schema_filter']]);
$definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]);
Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<xsd:attribute name="server-version" type="xsd:string" />
<xsd:attribute name="schema-manager-factory" type="xsd:string" />
<xsd:attribute name="use-savepoints" type="xsd:boolean" />
<xsd:attribute name="disable-type-comments" type="xsd:boolean" />
<xsd:attributeGroup ref="driver-config" />
</xsd:attributeGroup>

Expand Down
5 changes: 5 additions & 0 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Configuration Reference
# When true, profiling also collects schema errors for each query
profiling_collect_schema_errors: true
# When true, type comments are skipped in the database schema, matching the behavior of DBAL 4.
# This requires using the non-deprecated schema comparison APIs of DBAL.
disable_type_comments: false
server_version: ~
driver_class: ~
# Allows to specify a custom wrapper implementation to use.
Expand Down Expand Up @@ -417,6 +421,7 @@ Configuration Reference
profiling="%kernel.debug%"
profiling-collect-backtrace="false"
profiling-collect-schema-errors="true"
disable-type-comments="false"
server-version=""
driver-class=""
wrapper-class=""
Expand Down
20 changes: 20 additions & 0 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ public function testDbalLoadSavepointsForNestedTransactions(): void
$this->assertCount(0, $calls);
}

public function testDbalLoadDisableTypeComments(): void
{
$container = $this->loadContainer('dbal_disable_type_comments');

$calls = $container->getDefinition('doctrine.dbal.no_comments_connection.configuration')->getMethodCalls();
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
$this->assertCount(1, $calls);
$this->assertEquals('setDisableTypeComments', $calls[0][0]);
$this->assertTrue($calls[0][1][0]);

$calls = $container->getDefinition('doctrine.dbal.comments_connection.configuration')->getMethodCalls();
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
$this->assertCount(1, $calls);
$this->assertFalse($calls[0][1][0]);

$calls = $container->getDefinition('doctrine.dbal.notset_connection.configuration')->getMethodCalls();
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
$this->assertCount(0, $calls);
}

/** @group legacy */
public function testDbalSchemaManagerFactory(): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="no_comments">
<connection
name="no_comments"
disable-type-comments="true" />
<connection
name="comments"
disable-type-comments="false" />
<connection
name="notset"
user="root" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
doctrine:
dbal:
default_connection: no_comments
connections:
no_comments:
disable_type_comments: true
comments:
disable_type_comments: false
notset:
user: root
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"require": {
"php": "^7.4 || ^8.0",
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/dbal": "^3.6.0",
"doctrine/dbal": "^3.7.0",
"doctrine/persistence": "^2.2 || ^3",
"doctrine/sql-formatter": "^1.0.1",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
Expand Down

0 comments on commit cae8e39

Please sign in to comment.