Skip to content

Commit cae8e39

Browse files
committed
Add support for disabling type comments in the schema
1 parent d0e2a33 commit cae8e39

File tree

8 files changed

+66
-1
lines changed

8 files changed

+66
-1
lines changed

DependencyInjection/Configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
217217
->defaultValue(true)
218218
->info('Enables collecting schema errors when profiling is enabled')
219219
->end()
220+
->booleanNode('disable_type_comments')->end()
220221
->scalarNode('server_version')->end()
221222
->scalarNode('driver_class')->end()
222223
->scalarNode('wrapper_class')->end()

DependencyInjection/DoctrineExtension.php

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
250250

251251
unset($connection['auto_commit']);
252252

253+
if (isset($connection['disable_type_comments'])) {
254+
$configuration->addMethodCall('setDisableTypeComments', [$connection['disable_type_comments']]);
255+
}
256+
257+
unset($connection['disable_type_comments']);
258+
253259
if (isset($connection['schema_filter']) && $connection['schema_filter']) {
254260
$definition = new Definition(RegexSchemaAssetFilter::class, [$connection['schema_filter']]);
255261
$definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]);

Resources/config/schema/doctrine-1.0.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<xsd:attribute name="server-version" type="xsd:string" />
4141
<xsd:attribute name="schema-manager-factory" type="xsd:string" />
4242
<xsd:attribute name="use-savepoints" type="xsd:boolean" />
43+
<xsd:attribute name="disable-type-comments" type="xsd:boolean" />
4344
<xsd:attributeGroup ref="driver-config" />
4445
</xsd:attributeGroup>
4546

Resources/doc/configuration.rst

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ Configuration Reference
113113
# When true, profiling also collects schema errors for each query
114114
profiling_collect_schema_errors: true
115115
116+
# When true, type comments are skipped in the database schema, matching the behavior of DBAL 4.
117+
# This requires using the non-deprecated schema comparison APIs of DBAL.
118+
disable_type_comments: false
119+
116120
server_version: ~
117121
driver_class: ~
118122
# Allows to specify a custom wrapper implementation to use.
@@ -417,6 +421,7 @@ Configuration Reference
417421
profiling="%kernel.debug%"
418422
profiling-collect-backtrace="false"
419423
profiling-collect-schema-errors="true"
424+
disable-type-comments="false"
420425
server-version=""
421426
driver-class=""
422427
wrapper-class=""

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,26 @@ public function testDbalLoadSavepointsForNestedTransactions(): void
249249
$this->assertCount(0, $calls);
250250
}
251251

252+
public function testDbalLoadDisableTypeComments(): void
253+
{
254+
$container = $this->loadContainer('dbal_disable_type_comments');
255+
256+
$calls = $container->getDefinition('doctrine.dbal.no_comments_connection.configuration')->getMethodCalls();
257+
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
258+
$this->assertCount(1, $calls);
259+
$this->assertEquals('setDisableTypeComments', $calls[0][0]);
260+
$this->assertTrue($calls[0][1][0]);
261+
262+
$calls = $container->getDefinition('doctrine.dbal.comments_connection.configuration')->getMethodCalls();
263+
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
264+
$this->assertCount(1, $calls);
265+
$this->assertFalse($calls[0][1][0]);
266+
267+
$calls = $container->getDefinition('doctrine.dbal.notset_connection.configuration')->getMethodCalls();
268+
$calls = array_values(array_filter($calls, static fn ($call) => $call[0] === 'setDisableTypeComments'));
269+
$this->assertCount(0, $calls);
270+
}
271+
252272
/** @group legacy */
253273
public function testDbalSchemaManagerFactory(): void
254274
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
3+
<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:srv="http://symfony.com/schema/dic/services"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
8+
9+
<config>
10+
<dbal default-connection="no_comments">
11+
<connection
12+
name="no_comments"
13+
disable-type-comments="true" />
14+
<connection
15+
name="comments"
16+
disable-type-comments="false" />
17+
<connection
18+
name="notset"
19+
user="root" />
20+
</dbal>
21+
</config>
22+
</srv:container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
doctrine:
2+
dbal:
3+
default_connection: no_comments
4+
connections:
5+
no_comments:
6+
disable_type_comments: true
7+
comments:
8+
disable_type_comments: false
9+
notset:
10+
user: root

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"require": {
3232
"php": "^7.4 || ^8.0",
3333
"doctrine/cache": "^1.11 || ^2.0",
34-
"doctrine/dbal": "^3.6.0",
34+
"doctrine/dbal": "^3.7.0",
3535
"doctrine/persistence": "^2.2 || ^3",
3636
"doctrine/sql-formatter": "^1.0.1",
3737
"symfony/cache": "^5.4 || ^6.0 || ^7.0",

0 commit comments

Comments
 (0)