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

Change int primary keys to bigint #1088

Merged
merged 1 commit into from
Feb 9, 2023
Merged

Conversation

Mr0grog
Copy link
Member

@Mr0grog Mr0grog commented Feb 9, 2023

Integer primary keys can cause problems over time on big tables, and in general it's just better practice to use bigints instead. Some of our larger tables use UUIDs instead of ints, so this only upgrades the tables that used ints. (Practically speaking, none of these tables are really likely to overflow their primary key sequence, but better safe than sorry here, especially with technical maintainers offboarding.)

Fixes #1067.

Integer primary keys can cause problems over time on big tables, and in general it's just better practice to use bigints instead. Some of our larger tables use UUIDs instead of ints, so this only upgrades the tables that used ints. (Practically speaking, none of these tables are really *likely* to overflow their primary key sequence, but better safe than sorry here, especially with technical maintainers offboarding.)

Fixes #1067.
@Mr0grog
Copy link
Member Author

Mr0grog commented Feb 9, 2023

I noticed schema.rb doesn’t record anything about the sequences, and since this doesn't make things :bigserial, was worried a fresh DB would potentially be missing the sequences.

Tried this and and it appears to create the sequences and hook them up to the PK columns correctly, though:

# NOTE: delete the old DB or change the DB name in database.yaml first!
rails db:create
rails db:schema:load

@Mr0grog Mr0grog merged commit d12fa29 into main Feb 9, 2023
@Mr0grog Mr0grog deleted the 1067-integers-are-bad-primary-keys branch February 9, 2023 23:52
Mr0grog added a commit that referenced this pull request Feb 9, 2023
Mr0grog added a commit to edgi-govdata-archiving/web-monitoring-ops that referenced this pull request Feb 10, 2023
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.

Use bigint for all non-uuid primary keys
1 participant