-
Notifications
You must be signed in to change notification settings - Fork 471
Change report ID columns to BIGINT to avoid 32-bit integer overflow #4936
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
+229
−18
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
web/server/codechecker_server/migrations/report/versions/a7f3c8e21b90_report_id_bigint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """ | ||
| Report id bigint | ||
|
|
||
| Revision ID: a7f3c8e21b90 | ||
| Revises: 24c9660f82b1 | ||
| Create Date: 2026-06-30 00:00:00.000000 | ||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # Revision identifiers, used by Alembic. | ||
| revision = 'a7f3c8e21b90' | ||
| down_revision = '24c9660f82b1' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| REPORT_ID_FK_TABLES = [ | ||
| ('bug_path_events', False), | ||
| ('bug_report_points', False), | ||
| ('extended_report_data', False), | ||
| ('report_analysis_info', True), | ||
| ('report_annotations', False), | ||
| ] | ||
|
|
||
|
|
||
| def _alter_report_id_columns(type_, existing_type): | ||
| for table, nullable in REPORT_ID_FK_TABLES: | ||
| op.alter_column( | ||
| table, | ||
| 'report_id', | ||
| existing_type=existing_type, | ||
| type_=type_, | ||
| existing_nullable=nullable) | ||
|
|
||
|
|
||
| def upgrade(): | ||
| ctx = op.get_context() | ||
| dialect = ctx.dialect.name | ||
|
|
||
| if dialect == 'postgresql': | ||
| _alter_report_id_columns(sa.BigInteger(), sa.Integer()) | ||
| op.alter_column( | ||
| 'reports', | ||
| 'id', | ||
| existing_type=sa.Integer(), | ||
| type_=sa.BigInteger(), | ||
| existing_nullable=False, | ||
| autoincrement=True) | ||
| op.execute(sa.text('ALTER SEQUENCE reports_id_seq AS BIGINT')) | ||
| elif dialect == 'sqlite': | ||
| # SQLite INTEGER columns already store 64-bit signed integers. | ||
| pass | ||
|
|
||
|
|
||
| def downgrade(): | ||
| ctx = op.get_context() | ||
| dialect = ctx.dialect.name | ||
|
|
||
| if dialect == 'postgresql': | ||
| _alter_report_id_columns(sa.Integer(), sa.BigInteger()) | ||
| op.alter_column( | ||
| 'reports', | ||
| 'id', | ||
| existing_type=sa.BigInteger(), | ||
| type_=sa.Integer(), | ||
| existing_nullable=False, | ||
| autoincrement=True) | ||
| op.execute(sa.text('ALTER SEQUENCE reports_id_seq AS INTEGER')) | ||
| elif dialect == 'sqlite': | ||
| pass | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this column be NULL? Couldn't we set all
report_idforeign key columns as not nullable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. report_id being nullable is not intentional - it was defined that way in the original dabc6998b8f0 migration when report_analysis_info was added, but the application never creates rows without a report_id. If there's no analysis info for a report, no association row is created at all.
I agree we should tighten this. If you want I can do it in this PR or a seperate one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if this would be redesigned in this PR. Thank you in advance!