Skip to content

Commit f3a9806

Browse files
turegjorupclaude
andcommitted
feat: ignore deferred Template columns in schema:validate
Adds a postGenerateSchemaTable listener that injects icon, resources, and description into the in-memory schema for the `template` table before validate runs the entity-vs-DB diff. The columns are kept by the consolidated 3.0 migration (so fresh installs and 2.x → 3.0 upgraders end up with the same schema), but the 3.0 Template entity no longer maps them — without the listener, schema:validate would exit non-zero and fail the doctrine.yaml PR workflow. The listener is scoped to 3.0.x only. TODO[3.1] markers on both the class and the service registration call out that this listener and the deferred column-drop migration must land together in 3.1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 488b81e commit f3a9806

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

config/services.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ services:
191191
App\EventListener\ThemeDoctrineEventListener:
192192
tags: [doctrine.orm.entity_listener]
193193

194+
# Suppresses `doctrine:schema:validate` complaints about three `template`
195+
# columns the 3.0 `Template` entity no longer maps but the consolidated
196+
# 3.0 migration still creates (icon, resources, description). See the
197+
# listener class for the full rationale.
198+
#
199+
# TODO[3.1]: Remove this service registration together with the listener
200+
# class itself when the deferred column-drop migration ships in 3.1.
201+
App\EventListener\LegacyTemplateColumnsSchemaListener:
202+
tags:
203+
- { name: doctrine.event_listener, event: postGenerateSchemaTable }
204+
194205
App\Service\MediaUploadTenantDirectoryNamer:
195206
public: true
196207

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\EventListener;
6+
7+
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
8+
9+
/**
10+
* Reconciles `doctrine:schema:validate` with the consolidated 3.0 migration.
11+
*
12+
* The 3.0 release squashes the historical 2.x migrations into a single
13+
* schema-dump migration that recreates the end-of-2.7 schema verbatim — including
14+
* three columns the 3.0 `Template` entity no longer maps:
15+
* - `template.icon`
16+
* - `template.resources`
17+
* - `template.description`
18+
*
19+
* Keeping those columns in the consolidated migration keeps fresh installs and
20+
* 2.x → 3.0 upgraders symmetric (both end up with the columns), so the deferred
21+
* drop migration can run uniformly in 3.1. The price is that, without help,
22+
* `doctrine:schema:validate` reports the three columns as "extra in DB" and
23+
* exits non-zero — which the `doctrine.yaml` PR workflow treats as a failure.
24+
*
25+
* This listener fires on `postGenerateSchemaTable` for the `template` table and
26+
* adds the three legacy columns to the in-memory entity-side schema, so the
27+
* comparison against the actual DB sees no mismatch and validate exits clean.
28+
*
29+
* The same effect bleeds into `doctrine:migrations:diff`: while this listener
30+
* is registered, diff will not generate a "drop these columns" migration,
31+
* because it believes the entity wants them.
32+
*
33+
* TODO[3.1]: Delete this class together with the deferred Template column-drop
34+
* migration (originally `Version20250815092648`). Both must land in the same
35+
* 3.1 change so `migrations:diff` is no longer suppressed when the columns are
36+
* actually gone from the DB.
37+
*/
38+
final class LegacyTemplateColumnsSchemaListener
39+
{
40+
public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $args): void
41+
{
42+
$table = $args->getClassTable();
43+
44+
if ('template' !== $table->getName()) {
45+
return;
46+
}
47+
48+
$table->addColumn('icon', 'string', [
49+
'length' => 255,
50+
'notnull' => true,
51+
'default' => '',
52+
]);
53+
$table->addColumn('resources', 'json', [
54+
'notnull' => true,
55+
]);
56+
$table->addColumn('description', 'string', [
57+
'length' => 255,
58+
'notnull' => true,
59+
'default' => '',
60+
]);
61+
}
62+
}

0 commit comments

Comments
 (0)