[PR #11658] Create the default namespace in the schema #13168

Closed
opened 2026-01-22 16:16:24 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/11658

State: closed
Merged: No


This patch should address https://github.com/doctrine/migrations/issues/1415.

Problem details

  1. When the Postgres schema manager introspects a deployed schema, it creates the namespace with the name corresponding to the value of current_schema() in the Schema.
  2. When SchemaTool generates the schema to be deployed, it doesn't create the default namespace.

As a result, we have a mismatch in the list of schemas between the "from" and "to" schemas.

Solution

Instead of the approach proposed in https://github.com/doctrine/dbal/issues/5609, here, we add the default namespace obtain from the schema configuration, to the schema. This replicates the behavior of the schema manager.

Alternatives

As an option, the DBAL Schema could automatically create the namespace with the name from configuration in its constructor. There are certain difficulties with that:

  1. Prior to DBAL 4, the schema configuration name is not only set to the value of the current schema for Postgres, but is also set to the name of the current database for all other databases. Implementing the fix in DBAL prior to 4.0 will likely introduce a regression for all other platforms except for Postgres.
  2. Prior to DBAL 4, the schema configuration name is equal not to the current schema name but to the first value from the search path, (which by default is postgres).
  3. The operation of adding a namespace to the schema is not idempotent. So if we register the namespace in the constructor, then the subsequent call to createNamespace with the same name (as the DBAL's schema manager does) will fail.

Limitations

This fix cannot be implemented in ORM 2.x which still supports DBAL 3.x, which has the issue #​2 from the above list.

**Original Pull Request:** https://github.com/doctrine/orm/pull/11658 **State:** closed **Merged:** No --- This patch should address https://github.com/doctrine/migrations/issues/1415. ## Problem details 1. When the Postgres schema manager introspects a deployed schema, it creates the namespace with the name corresponding to the value of `current_schema()` in the `Schema`. 2. When `SchemaTool` generates the schema to be deployed, it doesn't create the default namespace. As a result, we have a mismatch in the list of schemas between the "from" and "to" schemas. ## Solution Instead of the approach proposed in https://github.com/doctrine/dbal/issues/5609, here, we add the default namespace obtain from the schema configuration, to the schema. This replicates the behavior of the schema manager. ## Alternatives As an option, the DBAL `Schema` could automatically create the namespace with the name from configuration in its constructor. There are certain difficulties with that: 1. Prior to DBAL 4, the schema configuration name is not only set to the value of the current schema for Postgres, but is also set to the name of the current database for all other databases. Implementing the fix in DBAL prior to 4.0 will likely introduce a regression for all other platforms except for Postgres. 2. Prior to DBAL 4, the schema configuration name is equal not to the current schema name but to the first value from the search path, (which by default is `postgres`). 3. The operation of adding a namespace to the schema is not idempotent. So if we register the namespace in the constructor, then the subsequent call to `createNamespace` with the same name (as the DBAL's schema manager does) will fail. ## Limitations This fix cannot be implemented in ORM 2.x which still supports DBAL 3.x, which has the issue #​2 from the above list.
admin added the pull-request label 2026-01-22 16:16:24 +01:00
admin closed this issue 2026-01-22 16:16:25 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13168