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

@@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Text, JSON, UniqueConstraint
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Text, JSON, UniqueConstraint, BigInteger
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from .database import Base
@@ -10,7 +10,7 @@ class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
telegram_id = Column(Integer, unique=True, nullable=False, index=True)
telegram_id = Column(BigInteger, unique=True, nullable=False, index=True)
username = Column(String(255))
first_name = Column(String(255))
last_name = Column(String(255))
@@ -180,7 +180,7 @@ class BannedUser(Base):
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
telegram_id = Column(Integer, nullable=False, index=True)
telegram_id = Column(BigInteger, nullable=False, index=True)
banned_by = Column(Integer, ForeignKey("users.id"), nullable=False)
reason = Column(Text, nullable=True)
banned_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))