Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions web/server/codechecker_server/database/run_db_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import os
from typing import Optional

from sqlalchemy import Boolean, Column, DateTime, Enum, ForeignKey, Integer, \
LargeBinary, MetaData, String, UniqueConstraint, Table, Text, JSON
from sqlalchemy import BigInteger, Boolean, Column, DateTime, Enum, \
ForeignKey, Integer, LargeBinary, MetaData, String, UniqueConstraint, \
Table, Text, JSON
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import true, false
Expand Down Expand Up @@ -277,9 +278,9 @@ class BugPathEvent(Base):
file_id = Column(Integer, ForeignKey('files.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'), index=True)
report_id = Column(Integer, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
report_id = Column(BigInteger, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
index=True,
primary_key=True)

Expand Down Expand Up @@ -307,9 +308,9 @@ class BugReportPoint(Base):
file_id = Column(Integer, ForeignKey('files.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'), index=True)
report_id = Column(Integer, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
report_id = Column(BigInteger, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
index=True,
primary_key=True)

Expand All @@ -331,9 +332,9 @@ class ExtendedReportData(Base):

id = Column(Integer, autoincrement=True, primary_key=True)

report_id = Column(Integer, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
report_id = Column(BigInteger, ForeignKey('reports.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
index=True)

file_id = Column(Integer, ForeignKey('files.id', deferrable=True,
Expand Down Expand Up @@ -370,7 +371,7 @@ def __init__(self, line_begin, col_begin, line_end, col_end,
Base.metadata,
Column(
'report_id',
Integer,
BigInteger,
ForeignKey('reports.id',
deferrable=True,
initially="DEFERRED",
Expand All @@ -391,7 +392,7 @@ def __init__(self, line_begin, col_begin, line_end, col_end,
class Report(Base):
__tablename__ = 'reports'

id = Column(Integer, autoincrement=True, primary_key=True)
id = Column(BigInteger, autoincrement=True, primary_key=True)
file_id = Column(Integer, ForeignKey('files.id', deferrable=True,
initially="DEFERRED",
ondelete='CASCADE'),
Expand Down Expand Up @@ -497,7 +498,7 @@ def __init__(self, report_id: int, key: str, value: str):
self.value = value

report_id = Column(
Integer,
BigInteger,
ForeignKey("reports.id", ondelete="CASCADE"),
primary_key=True,
index=True)
Expand Down
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),

Copy link
Copy Markdown
Contributor

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_id foreign key columns as not nullable?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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!

('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
Loading