-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
PostgreSQL: Unclear upgrade instructions regarding identity generation (AUTO vs IDENTITY vs SEQUENCE) leads to unusable database #11248
Comments
If you start a new project with DBAL 4 and ORM 3, use IDENTITY. It will map to We recommend to do the upgrade TO DBAL 4 and ORM 3 while making sure you stay with SEQUENCE, then deploy, fix any issues you have with DBAL 4 and ORM 3. Then, if that works fine, you should look into switching from SEQUENCE to IDENTITY. Cc @jwage who is also discovering the upgrade path these days. |
I decided to leave my id mapped with the IDENTITY strategy instead of SEQUENCE until I can get upgraded. I'll ignore the deprecation until then. When I switch to ORM 3.0 and DBAL 4.0 I will run this migration at the same time https://www.doctrine-project.org/projects/doctrine-dbal/en/4.0/how-to/postgresql-identity-migration.html |
Great, thanks, that article was exactly what I was missing! I added a link to it in #11257 |
@jwage did you write this backwards?
the eventual strategy doctine wants to use in v4 is IDENTITY, so did you mean
thanks |
hmm maybe not, I think I understand now. All my entities are currently defined as strategy=IDENTITY despite reading all the docs and upgrade guides, i'm still a little confused on the path forward. using orm 2.19.5, dbal 3.8.4, and defining 3 entities, with AUTO, SEQUENCE, IDENTITY strategeies, <?php
declare(strict_types=1);
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'test_auto')]
#[ORM\Entity()]
class TestAuto
{
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id()]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
} <?php
declare(strict_types=1);
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'test_identity')]
#[ORM\Entity()]
class TestIdentity
{
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id()]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
} <?php
declare(strict_types=1);
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'test_sequence')]
#[ORM\Entity()]
class TestSequence
{
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id()]
#[ORM\GeneratedValue(strategy: 'SEQUENCE')]
private $id;
} we get a diff of: CREATE SEQUENCE test_sequence_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE SEQUENCE test_auto_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE test_sequence (id INT NOT NULL, PRIMARY KEY(id));
CREATE TABLE test_identity (id SERIAL NOT NULL, PRIMARY KEY(id));
CREATE TABLE test_auto (id INT NOT NULL, PRIMARY KEY(id)); so currently
I think we are saying that, in dbal 4, strategy IDENTITY will switch from |
To get the full picture, you actually need to consider the full picture, which involves 3 strategies:
In DBAL 3 and older, the To me, the unclear part about the deprecation is related to the fact that we have multiple cases to consider:
@greg0ire in DBAL 3, |
Sorry, when I wrote that CREATE TABLE tablename (
colname SERIAL
); is equivalent to specifying CREATE SEQUENCE tablename_colname_seq AS integer;
CREATE TABLE tablename (
colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname; I called that an alias, which is by no means an official term and might be clumsy, sorry if it caused more confusion on an already confusing topic. |
BC Break Report
Summary
I have this mapping:
After upgrading to DBAL 4 and ORM 3, running
php bin/console make:migration
generates:When running this migration, I get:
foo_id_seq1
, additional tofoo_id_seq
(with "Current Value": 31) I already have.Then, obviously, when persisting a new entity, I'm getting:
Unclear Recommendations
Before upgrading, I got this deprecation:
Which (basically) says: Switch to
SEQUENCE
!On the other hand, https://github.com/doctrine/orm/blob/3.0.x/UPGRADE.md#bc-break-auto-keyword-for-identity-generation-defaults-to-identity-for-postgresql-when-using-doctrinedbal-4 says:
Which (basically) says: Doctrine recommends
IDENTITY
.Solution?
So the questions are:
The text was updated successfully, but these errors were encountered: