Skip to content

fix: keep foreign keys when collating key columns - #78

Merged
HecFranco merged 1 commit into
mainfrom
fix/schema-fk-collation
Nov 20, 2026
Merged

HecFranco merged 1 commit into
mainfrom
fix/schema-fk-collation

Conversation

@HecFranco

Copy link
Copy Markdown
Contributor

Audit XI (latent, no GHSA). Proposed patch: 1.23.1.

Problem

ExactColumnsCollationListener (1.20.1) replaced the entry table on postGenerateSchemaTable (setClassTable(), DBAL 4.5+). ORM 3.7–3.8 then adds the table's deferred foreign keys to the old table object, so any foreign key starting on the entry table (and its index) would be dropped on MySQL / MariaDB. The entry table has none today.

Fix (same pattern as ContactForm 100cf3c)

  • The listener runs on postGenerateSchema, once every foreign key exists, by table name. The service tag is updated.
  • DBAL 4.5+: the table is rebuilt with its editor and swapped in with GenerateSchemaEventArgs::setSchema(). Older DBAL: column options are set in place.
  • The platform comes from the schema tool's entity manager, and managers that don't map the entry are skipped. postGenerateSchemaTable() stays as a deprecated no-op. The ManagerRegistry argument is now optional and unused. The collations and the PAD SPACE warning are unchanged. The listener is stateless (worker mode with kernel reset off), and no host entity manager is cleared, reset or closed.

Also (Beacon request)

RollupTables::addTo() now sets the primary keys with Table::addPrimaryKeyConstraint() where DBAL has it (4.3+). setPrimaryKey() is kept as the fallback for older DBAL. The key is the same. A new RollupTablesPrimaryKeyTest asserts that no doctrine/dbal#6867 deprecation is raised.
Note: on DBAL 4.5+, addPrimaryKeyConstraint() and the other mutable Table / Schema calls in addTo() raise the newer doctrine/dbal#7389 / #7373 deprecations. Clearing those needs addTo() rewritten on the editor API, which is left as a follow-up.

Tests

  • A foreign key and an index added to the entry table are kept, and the identifier columns are still collated.
  • Foreign key and index parity, with and without the listener, on MySQL 8.4, MySQL 8.0, MySQL 5.7, the replica set, MariaDB and SQLite.
  • Skipped managers and tables, and the deprecated no-op.
  • A real-DB check that the created entry / rollup tables match the generated schema. It runs in the existing MySQL 8.4 / MariaDB 11.4 ExactCollationTest steps.

Local results (CI commands, Docker)

  • php-cs-fixer, PHPStan, Rector dry-run: clean. Igor: 0 KO (the 1 WARN is pre-existing, in MailerCaptureListener).
  • composer test (PHP 8.4): 1009 OK (87 skipped without servers). Coverage cell (PHP 8.2, Symfony 7.4): 5600/5600 = 100%.
  • --group database --fail-on-skipped: 18 OK on DBAL 4.6 and on DBAL 3.10.
  • Integration suite on MySQL 8.4 + PostgreSQL 16 and on MariaDB 11.4 + PostgreSQL 16, both on DBAL 4.6 and on DBAL 3.10: 320 OK each. Only the allowed skips occurred (perf ×2, DBAL-conversion ×1). The 2 fputcsv() deprecations and the phpunit.xml schema notice are pre-existing.

🤖 Generated with Claude Code

ExactColumnsCollationListener replaced the entry table on
postGenerateSchemaTable with setClassTable() (DBAL 4.5+); ORM 3.7-3.8 then
added the table's foreign keys to the replaced object, so any foreign key
starting on the entry table, and its index, was lost on MySQL / MariaDB. None
exists today (latent, audit XI).

The listener now runs on postGenerateSchema once every foreign key exists: on
DBAL 4.5+ the table is rebuilt with its editor and swapped in with
GenerateSchemaEventArgs::setSchema(); older DBAL sets the column options in
place. The platform comes from the schema tool's entity manager and managers
that do not map the entry are skipped. postGenerateSchemaTable() stays as a
deprecated no-op. Same collations and fallback warning.

The rollup tables also get their primary key through
Table::addPrimaryKeyConstraint() where DBAL has it (4.3+), keeping
setPrimaryKey() for older DBAL, so building them no longer raises the
setPrimaryKey() deprecation (doctrine/dbal#6867).
@github-actions

Copy link
Copy Markdown

@coderabbitai review

@HecFranco
HecFranco merged commit b27913d into main Nov 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant