Repository navigation
Store the metadata with DBAL in a table the bundle owns - #40
Merged
Merged
Conversation
The metadata store wrote through the application's entity manager, so its flush also wrote every change the application made to its managed entities without flushing it, and a failed INSERT closed that entity manager (#16). DoctrineDbalBasedMetadataStore replaces DoctrineOrmBasedMetadataStore. It reads and writes the table setono_client__metadata (client_id, metadata) with DBAL on DoctrineBundle's default connection, which it gets as a service closure, so a request that doesn't use the metadata doesn't start the connection. A write is an UPDATE, and an INSERT when no row matched. The INSERT runs in a transaction, so when it fails inside a transaction of the application, it rolls back to a savepoint instead of aborting the application's transaction on PostgreSQL. MetadataTableSchemaListener adds the table to the schema of the entity managers on that connection, so migrations create it. The bundle has no entity anymore: Entity\Metadata, Entity\MetadataInterface, the metadata_class option, both mappings and the compile-time switch between them are gone, with the custom_metadata and interface_only_metadata test environments. A table created under DoctrineBundle's default naming strategy has the column clientId, which the next generated migration renames to client_id. Closes #16 Closes #39
Without setono/doctrine-orm-trait, whose constraint ruled out ORM 3.0, Composer's lowest dependencies resolve ORM 3.0.0: they pick doctrine/cache 1.11.0 and symfony/polyfill-php80 1.15.0, which ORM 2.17 doesn't accept. So no job tested ORM 2 anymore. The PHP 8.1 lowest unit test job now pins doctrine/orm ~2.17.0, while the PHP 8.2 lowest jobs keep testing ORM 3.0.
This was referenced Nov 30, 2026
The metadata store sends its own SQL through DBAL now, and SQLite hides how MySQL and PostgreSQL handle it: PostgreSQL aborts the surrounding transaction when a statement fails, which only a manual run against PostgreSQL showed. A database test job runs the suite against MySQL 8.4 and PostgreSQL 16 service containers, with the lowest and the highest dependencies, through SETONO_CLIENT_BUNDLE_DATABASE_URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16, closes #39. Supersedes #38.
Summary
The metadata store reads and writes its own table with DBAL, so it never touches the application's entity manager. The bundle has no entity anymore: a schema listener puts the table into the schema Doctrine generates, like Symfony's session, cache, lock and Messenger tables.
Also gone: the
metadata_classoption, the compile-time switch between the two mappings,setono/doctrine-orm-trait, and thecustom_metadataandinterface_only_metadatatest environments. ADR-0005 records the decision and why #38's entity manager per write, keeping the mapping as the schema, and two schema code paths per DBAL version were rejected. The listener uses DBAL's schema API from before 4.5, which works on 3.7–4.x; DBAL 4.5 deprecates it silently unless the application enables doctrine/deprecations.The third commit pins
doctrine/orm ~2.17.0in the PHP 8.1 lowest unit test job. Withoutsetono/doctrine-orm-trait, whose constraint ruled out ORM 3.0, Composer's lowest dependencies resolve ORM 3.0.0, so nothing tested ORM 2 anymore.The fourth commit adds a database test job: the suite against MySQL 8.4 and PostgreSQL 16 service containers, with the lowest and the highest dependencies. The store sends its own SQL now, and SQLite hides how those databases handle it.
Two deviations from #39: the concurrent INSERT is simulated with a DBAL
wrapper_class(ConcurrentInsertConnection, which inserts the row right after the store's UPDATE) instead of a middleware, andUPGRADE-2.0.mdsays the next generated migration renamesclientId, because it does (below), instead of asking for a rename by hand first.Evidence
Before: on 2.x,
MetadataTestasserted that a request using the metadata starts the entity manager, and Write the metadata through the store's own entity manager #38's test showed the store's flush writing another client's unflushed change.After:
it_stores_metadata_without_an_entity_managerstores metadata and asserts that no entity manager was started.Before:
MetadataTableTest::it_adds_the_metadata_table_to_the_schema_of_an_entity_manager_on_the_default_connectionfailed: the 2.x mapping gave the columnsclientIdandmetadata.After: it passes, and so do the tests that the table stays out of another connection's schema and that the created schema is in sync.
Before: on PostgreSQL,
it_keeps_the_row_of_a_concurrent_request_that_stored_it_firstfailed withSQLSTATE[25P02]: current transaction is aborted: the failed INSERT aborted the surrounding transaction.After: with the INSERT in
transactional(), it passes.The suite (98 tests) passes on SQLite, MySQL 8.4 and PostgreSQL 16 with the highest dependencies; on SQLite, MySQL and PostgreSQL with PHP 8.1, ORM 2.17.0, DBAL 3.7.0, DoctrineBundle 2.11.3 and Symfony 6.4.0; and on SQLite with PHP 8.2, ORM 3.0.0 and Symfony 7.0.0. PHPStan, ECS, composer validate/normalize and the dependency analyser pass. Infection: 100% MSI, 98 of 98 mutants killed.
The table as 2.x's mapping created it, compared with the listener's table, on MySQL 8.4 and PostgreSQL 16, with DBAL 3.7 and 4.5:
underscore_number_aware)CHANGE clientId client_id VARCHAR(255) NOT NULL(primary key dropped and added around it); PostgreSQL:RENAME COLUMN clientid TO client_idMerge Danger
Door: two-way
2.0 isn't released, so a revert restores the entity and the ORM store, and no application has run the column rename yet.
Blast Radius: schema
clientIdtoclient_id.UPGRADE-2.0.mdsays to check that it renames rather than drops the column.metadata_classcopy their rows intosetono_client__metadataand remove their own mapping of that table, or Doctrine fails to generate the schema.use_savepoints, a failed INSERT inside a transaction of the application still aborts it on PostgreSQL, as the ORM's flush did.MetadataStoreInterfacealias.