[PR #12148] docs: generation strategies: differences between DBAL 3 and 4 #13525

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

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

State: closed
Merged: Yes


Hello,
I'm currently updating Doctrine DBAL from version 3 to 4 on an app that uses Doctrine generated ID columns (with no strategy defined, thus using AUTO if I'm not mistaken) with PostgreSQL 17.

I suspect that the generation strategies' documentation for PostgreSQL is outdated or inaccurate, due to changes introduced in / for Doctrine DBAL 4.

Here's a more detailed report / explanation:

I initially encountered database errors about PostgreSQL's SEQUENCE, and tried tinkering with the strategy, to no avail.
I then stumbled upon the following documentation: https://github.com/doctrine/dbal/blob/4.3.x/docs/en/how-to/postgresql-identity-migration.rst

Still, something about the generation strategies' documentation confused me: the documentation claims that no matter Doctrine DBAL's version, the default (AUTO) strategy on PostgreSQL is SEQUENCE.

When tested on my app, either of these 2 lines produce the same database migrations:

#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\GeneratedValue]
ALTER TABLE my_table ALTER id DROP DEFAULT;
ALTER TABLE my_table ALTER id ADD GENERATED BY DEFAULT AS IDENTITY;

but the SEQUENCE strategy just seems to remove the DEFAULT:

#[ORM\GeneratedValue(strategy: 'SEQUENCE')]
ALTER TABLE my_table ALTER id DROP DEFAULT;

This behavior suggested that the default strategy on PostgreSQL would be IDENTITY and not SEQUENCE.

After digging into the code, it seems to be the case:

Thank you for reviewing my PR, tell me if there is anything wrong / that can be improved in it 👍
Thank you for all the work you did on Doctrine!

PS : Do these documentation changes need to be backported all the way back to ORM 3.0? The initial commit that introduced this difference seems to date back to ORM 3.0 RC 1: bdc039fe31

**Original Pull Request:** https://github.com/doctrine/orm/pull/12148 **State:** closed **Merged:** Yes --- Hello, I'm currently updating Doctrine DBAL from version 3 to 4 on an app that uses Doctrine generated ID columns (with no strategy defined, thus using `AUTO` if I'm not mistaken) with PostgreSQL 17. I suspect that the generation strategies' documentation for PostgreSQL is outdated or inaccurate, due to changes introduced in / for Doctrine DBAL 4. Here's a more detailed report / explanation: I initially encountered database errors about PostgreSQL's `SEQUENCE`, and tried tinkering with the strategy, to no avail. I then stumbled upon the following documentation: https://github.com/doctrine/dbal/blob/4.3.x/docs/en/how-to/postgresql-identity-migration.rst Still, something about the generation strategies' documentation confused me: the documentation claims that no matter Doctrine DBAL's version, the default (`AUTO`) strategy on PostgreSQL is `SEQUENCE`. When tested on my app, either of these 2 lines produce the same database migrations: ```php #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\GeneratedValue] ``` ```sql ALTER TABLE my_table ALTER id DROP DEFAULT; ALTER TABLE my_table ALTER id ADD GENERATED BY DEFAULT AS IDENTITY; ``` but the `SEQUENCE` strategy just seems to remove the `DEFAULT`: ```php #[ORM\GeneratedValue(strategy: 'SEQUENCE')] ``` ```sql ALTER TABLE my_table ALTER id DROP DEFAULT; ``` This behavior suggested that the default strategy on PostgreSQL would be `IDENTITY` and not `SEQUENCE`. After digging into the code, it seems to be the case: - PostgreSQL isn't listed in `NON_IDENTITY_DEFAULT_STRATEGY`: https://github.com/doctrine/orm/blob/21e9fcbfbbf9a72abd8bf0d3f3e9d8c397fb80f3/src/Mapping/ClassMetadataFactory.php#L63-L65 - but it is set only when using DBAL 3: https://github.com/doctrine/orm/blob/21e9fcbfbbf9a72abd8bf0d3f3e9d8c397fb80f3/src/Mapping/ClassMetadataFactory.php#L631-L634 - when using DBAL 4, the previous code isn't triggered, and falls back to `IDENTITY`: https://github.com/doctrine/orm/blob/21e9fcbfbbf9a72abd8bf0d3f3e9d8c397fb80f3/src/Mapping/ClassMetadataFactory.php#L666 - Doctrine DBAL's `PostgreSQLPlatform` then outputs `GENERATED BY DEFAULT AS IDENTITY`: https://github.com/doctrine/dbal/blob/1432ec68513bb1788d9ed4e7ace4f12f6595fb9c/src/Platforms/PostgreSQLPlatform.php#L276 Thank you for reviewing my PR, tell me if there is anything wrong / that can be improved in it :+1: Thank you for all the work you did on Doctrine! PS : Do these documentation changes need to be backported all the way back to ORM 3.0? The initial commit that introduced this difference seems to date back to ORM 3.0 RC 1: https://github.com/doctrine/orm/commit/bdc039fe314a85fb6c578e06c1dd7f7d383f06a7
admin added the pull-request label 2026-01-22 16:17:22 +01:00
admin closed this issue 2026-01-22 16:17:22 +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#13525