Skip to content

Fix sequences after migrating data to PostgreSQL#2466

Merged
matrss merged 1 commit intoOpen-MSS:developfrom
matrss:fix-postgresql-sequences-after-migration
Aug 21, 2024
Merged

Fix sequences after migrating data to PostgreSQL#2466
matrss merged 1 commit intoOpen-MSS:developfrom
matrss:fix-postgresql-sequences-after-migration

Conversation

@matrss
Copy link
Collaborator

@matrss matrss commented Aug 16, 2024

When inserting rows into PostgreSQL tables and explicitly setting values for e.g. auto-increment columns, like the IDs, the associated sequences aren't automatically updated. This means that without explicitly fixing the sequences PostgreSQL would try to insert new rows with existing values for the IDs, failing in the process due to unique constraints.

This issue doesn't affect MariaDB nor SQLite. The former automatically updates auto-increment counters on insert, the latter simply uses the last rows ID as a starting point.

This change also extends the tests to try adding a new user after the migration, which should catch this kind of issue.

Purpose of PR?:

Fixes #2465.

Does this PR introduce a breaking change?

If the changes in this PR are manually verified, list down the scenarios covered::

Additional information for reviewer? :
Mention if this PR is part of any design or a continuation of previous PRs

Does this PR results in some Documentation changes?
If yes, include the list of Documentation changes

Checklist:

  • Bug fix. Fixes #
  • New feature (Non-API breaking changes that adds functionality)
  • PR Title follows the convention of <type>: <subject>
  • Commit has unit tests

When inserting rows into PostgreSQL tables and explicitly setting values
for e.g. auto-increment columns, like the IDs, the associated sequences
aren't automatically updated. This means that without explicitly fixing
the sequences PostgreSQL would try to insert new rows with existing
values for the IDs, failing in the process due to unique constraints.

This issue doesn't affect MariaDB nor SQLite. The former automatically
updates auto-increment counters on insert, the latter simply uses the
last rows ID as a starting point.

This change also extends the tests to try adding a new user after the
migration, which should catch this kind of issue.
@matrss matrss requested a review from ReimarBauer August 16, 2024 13:33
Copy link
Member

@ReimarBauer ReimarBauer left a comment

Choose a reason for hiding this comment

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

verified on a psql server

@matrss matrss merged commit da36488 into Open-MSS:develop Aug 21, 2024
@matrss matrss deleted the fix-postgresql-sequences-after-migration branch August 21, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

develop: migration of an existing psql database does not keep the current index

2 participants