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
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:
71
migrations/versions/007_change_telegram_id_to_bigint.py
Normal file
71
migrations/versions/007_change_telegram_id_to_bigint.py
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user