Skip to content
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

Autoincrement via identity columns on PostgreSQL #5396

Merged
merged 1 commit into from May 15, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented May 15, 2022

Q A
Type improvement

See #4744. Fixes #3619, #4458, #4745, #5614 .

Note that in order to replicate the state of the serial column sequences in the identity columns, manual migration is required.
Without the above migration, the identity column sequences will be created from scratch and will produce values starting from 1.

The migration can be tested as:

  1. Create a test schema and some data using DBAL 3:
    $schema = new Schema();
    $table = $schema->createTable('ai');
    $table->addColumn('id', 'integer', ['autoincrement' => true]);
    
    $sm = $connection->createSchemaManager();
    $sm->migrateSchema($schema);
    
    for ($i = 0; $i < 3; $i++) {
        $connection->executeStatement('INSERT INTO ai (id) VALUES (DEFAULT)');
    }
  2. Confirm that the sequential numbers have been generated:
    SELECT id FROM ai;
    -- 1
    -- 2
    -- 3
  3. Perform the migration:
    SELECT upgrade_serial_to_identity('ai', 'id');
  4. Switch to DBAL 4.
  5. Execute the script from step 1 again.
  6. Confirm that the sequence is preserved:
    SELECT id FROM ai;
    -- 1
    -- 2
    -- 3
    -- 4
    -- 5
    -- 6

@morozov
Copy link
Member Author

morozov commented May 15, 2022

We need to move the migration steps to the documentation, although I'm not sure where exactly. @greg0ire do you have any ideas?

@greg0ire
Copy link
Member

greg0ire commented May 15, 2022

I guess you're implying these migration steps are too long to be included in UPGRADE.md? I think they would qualify as a how-to guide. Let's create docs/en/how-to and put them there, then? And then link to these docs from UPGRADE.md?

greg0ire
greg0ire previously approved these changes May 15, 2022
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simplifies the code nicely 🙂

@morozov morozov linked an issue May 15, 2022 that may be closed by this pull request
@morozov morozov merged commit a4338b7 into doctrine:4.0.x May 15, 2022
@morozov morozov deleted the pgsql-identity branch May 16, 2022 20:39
@morozov morozov added this to the 3.4.0 milestone Jun 3, 2022
@morozov morozov modified the milestones: 3.4.0, 4.0.0 Aug 3, 2022
@greg0ire greg0ire linked an issue Aug 23, 2022 that may be closed by this pull request
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants