Skip to content

db-dump: Reset sequences after data import #11506

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

Merged
merged 1 commit into from
Jul 4, 2025
Merged

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Jul 3, 2025

This automatically resets all id column sequences to the maximum id column value of the corresponding table after the data was imported.

Closes #10204

@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Jul 3, 2025
@Turbo87 Turbo87 requested a review from a team July 3, 2025 13:27
Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

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

The SQL looks correct to me :D

Comment on lines 29 to 30
-- Reset the sequence to the max value
PERFORM setval('public.' || rec.sequence_name, max_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, it might be worth commenting that the next value will be the set max_id + 1. This is because setval has two modes controlled by its optional third argument (which defaults to true), determining whether to add 1 to the next value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I slightly changed it to explicitly use the third argument. Without this for empty tables the next value would have been 2 instead of 1. I hope that makes it a bit clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yeah, you're right, thanks for the noticing!

This automatically resets all `id` column sequences to the maximum `id` column value of the corresponding table after the data was imported.
@Turbo87 Turbo87 merged commit 0f060e2 into rust-lang:main Jul 4, 2025
11 checks passed
@Turbo87 Turbo87 deleted the pg-seqs branch July 4, 2025 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants