From acb56c8b0d55044389555e39e50a790e34570c72 Mon Sep 17 00:00:00 2001 From: Aidar Garikhanov Date: Sat, 26 Oct 2024 12:59:43 +0300 Subject: [PATCH] Make telegram ID identifier big integer (int64) --- ...257-249977e15076_make_telegram_id_int64.py | 31 +++++++++++++++++++ tests/test_user_repo.py | 2 +- vkusvill_green_labels/core/settings.py | 4 ++- vkusvill_green_labels/models/db/user.py | 4 +-- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/2024_10_26_1257-249977e15076_make_telegram_id_int64.py diff --git a/migrations/versions/2024_10_26_1257-249977e15076_make_telegram_id_int64.py b/migrations/versions/2024_10_26_1257-249977e15076_make_telegram_id_int64.py new file mode 100644 index 0000000..a554295 --- /dev/null +++ b/migrations/versions/2024_10_26_1257-249977e15076_make_telegram_id_int64.py @@ -0,0 +1,31 @@ +"""Make telegram id int64 + +Revision ID: 249977e15076 +Revises: 272acf3925ed +Create Date: 2024-10-26 12:57:00.043010 + +""" + +from collections.abc import Sequence + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "249977e15076" +down_revision: str | None = "272acf3925ed" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + op.alter_column( + "users", "tg_id", existing_type=sa.INTEGER(), type_=sa.BigInteger(), existing_nullable=False + ) + + +def downgrade() -> None: + op.alter_column( + "users", "tg_id", existing_type=sa.BigInteger(), type_=sa.INTEGER(), existing_nullable=False + ) diff --git a/tests/test_user_repo.py b/tests/test_user_repo.py index 23ed0d3..2617fbd 100644 --- a/tests/test_user_repo.py +++ b/tests/test_user_repo.py @@ -70,7 +70,7 @@ async def test_create_users_with_settings( test_session: AsyncSession, user_repository: UserRepository ): # Arrange - tg_id = 1 + tg_id = 8240784014 user = User( tg_id=tg_id, settings=UserSettings( diff --git a/vkusvill_green_labels/core/settings.py b/vkusvill_green_labels/core/settings.py index 00331ef..ad2c08a 100644 --- a/vkusvill_green_labels/core/settings.py +++ b/vkusvill_green_labels/core/settings.py @@ -105,6 +105,8 @@ def validate_environment(cls, v: str | None) -> str | None: class WebServerSettings(BaseSettings): + model_config = SettingsConfigDict(extra="ignore") + host: str = "127.0.0.1" port: int = 8080 @@ -117,7 +119,7 @@ class Settings(BaseSettings): database: DatabaseSettings redis: RedisSettings sentry: SentrySettings - web_server: WebServerSettings + web_server: WebServerSettings = WebServerSettings() log_level: str = "INFO" update_interval: int = Field(..., description="Update interval in seconds") diff --git a/vkusvill_green_labels/models/db/user.py b/vkusvill_green_labels/models/db/user.py index cc57252..d5373cf 100644 --- a/vkusvill_green_labels/models/db/user.py +++ b/vkusvill_green_labels/models/db/user.py @@ -2,7 +2,7 @@ from uuid import uuid4 -from sqlalchemy import UUID, ForeignKey +from sqlalchemy import UUID, BigInteger, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from vkusvill_green_labels.models.db.base import Base @@ -18,7 +18,7 @@ class User(Base): __tablename__ = "users" id: Mapped[UserID] = mapped_column(UUID, default=uuid4, primary_key=True) - tg_id: Mapped[int] = mapped_column(index=True, unique=True) + tg_id: Mapped[int] = mapped_column(BigInteger, index=True, unique=True) first_name: Mapped[str | None] last_name: Mapped[str | None] username: Mapped[str | None]