diff --git a/alembic/versions/d371333159ab_video_view_count_bigint.py b/alembic/versions/d371333159ab_video_view_count_bigint.py new file mode 100644 index 00000000..9674ae54 --- /dev/null +++ b/alembic/versions/d371333159ab_video_view_count_bigint.py @@ -0,0 +1,29 @@ +"""Video view_count bigint. + +Revision ID: d371333159ab +Revises: b2b9700f5048 +Create Date: 2026-02-08 + +This migration changes the view_count column from INTEGER to BIGINT +to accommodate YouTube videos with view counts exceeding 2,147,483,647. +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'd371333159ab' +down_revision = 'b2b9700f5048' +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column('video', 'view_count', + existing_type=sa.Integer(), + type_=sa.BigInteger()) + + +def downgrade(): + op.alter_column('video', 'view_count', + existing_type=sa.BigInteger(), + type_=sa.Integer()) diff --git a/modules/videos/common.py b/modules/videos/common.py index 15c16144..3eacdc2d 100644 --- a/modules/videos/common.py +++ b/modules/videos/common.py @@ -351,7 +351,7 @@ async def update_view_counts_and_censored(channel_id: int): with get_db_curs(commit=True) as curs: # Update the view_count for each video. stmt = ''' - WITH source AS (select * from json_to_recordset(%s::json) as (id text, view_count int)) + WITH source AS (select * from json_to_recordset(%s::json) as (id text, view_count bigint)) UPDATE video SET view_count = s.view_count FROM source as s diff --git a/modules/videos/models.py b/modules/videos/models.py index 6a567381..e352f143 100644 --- a/modules/videos/models.py +++ b/modules/videos/models.py @@ -34,7 +34,7 @@ class Video(ModelHelper, Base): id = Column(Integer, primary_key=True) source_id = Column(String) # The id from yt-dlp - view_count = Column(Integer) # The view count from the ChannelDownloader (or from initial download) + view_count = Column(BigInteger) # The view count from the ChannelDownloader (or from initial download) ffprobe_json = deferred(Column(JSONB)) # Data that is fetched once from ffprobe (ffmpeg) have_comments = Column(Boolean, default=False) # see `get_missing_videos_comments` comments_failed = Column(Boolean, default=False) # see `get_missing_videos_comments`