fix: change telegram_id from INTEGER to BIGINT to support large bot IDs
Some checks reported errors
continuous-integration/drone/push Build encountered an error

- Add migration 007 to change users.telegram_id from INTEGER to BIGINT
- Update User.telegram_id model to use BigInteger
- Update BannedUser.telegram_id model to use BigInteger
- Fixes asyncpg.exceptions.DataError: value 8300330445 out of int32 range
- PostgreSQL INTEGER supports only -2.1B to 2.1B, but Telegram IDs can exceed this
- BIGINT supports up to 9.2 quintillion, sufficient for all Telegram IDs
This commit is contained in:
2025-11-17 06:15:20 +09:00
parent 3d7338b3ed
commit d3f9f2fb53
2 changed files with 74 additions and 3 deletions

View File

@@ -0,0 +1,71 @@
"""Change telegram_id from INTEGER to BIGINT
Revision ID: 007
Revises: 006
Create Date: 2025-11-17 06:10:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '007'
down_revision = '006'
branch_labels = None
depends_on = None
def upgrade() -> None:
"""
Изменяем тип telegram_id с INTEGER (int32) на BIGINT (int64)
для поддержки больших ID телеграм ботов (например, 8300330445).
PostgreSQL INTEGER поддерживает диапазон от -2,147,483,648 до 2,147,483,647.
Telegram ID могут превышать это значение, что вызывает ошибку:
"invalid input for query argument: value out of int32 range"
BIGINT поддерживает диапазон от -9,223,372,036,854,775,808 до 9,223,372,036,854,775,807.
"""
# Изменяем telegram_id в таблице users
op.alter_column(
'users',
'telegram_id',
existing_type=sa.INTEGER(),
type_=sa.BIGINT(),
existing_nullable=False
)
# Изменяем telegram_id в таблице banned_users
op.alter_column(
'banned_users',
'telegram_id',
existing_type=sa.INTEGER(),
type_=sa.BIGINT(),
existing_nullable=False
)
def downgrade() -> None:
"""
Откатываем изменения обратно на INTEGER.
ВНИМАНИЕ: Если в базе есть значения > 2,147,483,647, откат не удастся!
"""
# Откатываем telegram_id в таблице users
op.alter_column(
'users',
'telegram_id',
existing_type=sa.BIGINT(),
type_=sa.INTEGER(),
existing_nullable=False
)
# Откатываем telegram_id в таблице banned_users
op.alter_column(
'banned_users',
'telegram_id',
existing_type=sa.BIGINT(),
type_=sa.INTEGER(),
existing_nullable=False
)