-
-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrations Diff and ORM Schema commands use schema_filter config differently #1487
Comments
This was referenced Feb 9, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 27, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 27, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 27, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 27, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 27, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
cristi-contiu
added a commit
to cristi-contiu/doctrine-migrations
that referenced
this issue
Feb 28, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Summary
With PostgreSQL, the migrations diff command does not include expected create table queries for tables not in
public
schema when usingdoctrine.dbal.schema_filter
config. The ORM's schema update and validate commands include these queries.Current behavior
When building the diff, the
DiffGenerator->createToSchema()
removes the schema name from the table name (inDiffGenerator->resolveTableName
) before passing it to the$schemaAssetsFilter
to be matched against the regex inschema_filter
. The ORM's schema generation keeps the schema name if it's not the default (search path) schema (usually thepublic
schema), so two different names for the same table will be matched against the regex, with and without the schema name.I would suggest aligning the way the
schema_filter
is used by not removing the schema name (if any) from the table name before sending it to the$schemaAssetsFilter
. This can be done simply by not callingDiffGenerator->resolveTableName
inDiffGenerator->createToSchema()
. I'm not sure about backwards compatibility implications on other database vendors.It's also worth mentioning that both the ORM and Migrations commands get from the DBAL schema introspection an already filtered version of the database schema and the ORM commands do not apply filtering to the schema created from metadata - if a table is added to the mappings, it is honored and tracked even if it does not match the regex in
schema_filter
. Theschema_filter
config can be used only to ignore tables in the database, not as a way to exclude tables from the ORM's mapping metadata. To align these behaviours would mean to remove any extra operations on$toSchema
inDiffGenerator->createToSchema()
and to make an extra check in$fromSchema
before applying the filtering.How to reproduce
In a blank Symfony 7.2 project with Docker support, DoctrineBundle and PostgreSQL, add
schema_filter
set inconfig/packages/doctrine.yaml
to filter tables by schema name:Add a new Entity inside that schema:
Running the migrations diff command generates a migration with an empty
up
method because "customer" does not match regex~^app_schema\.~
:The ORM commands properly identify the table that needs creating, as they match "app_schema.customer" against
~^app_schema\.~
:If a migration was manually created with the query above and executed, the next migrations generated from diff would always contain a
DROP TABLE app_schema.customer
query.Expected behavior
The diff migration should contain the create table query identified by the schema update command:
Likewise, if the migration was manually created with the
CREATE TABLE
query and executed, the following migrations generated from diff should not contain theDROP TABLE
query.The text was updated successfully, but these errors were encountered: