mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-18 02:30:39 +03:00
remove models update from migrations (#80)
* add bot models update script * add last question at field * update README.md
This commit is contained in:
@@ -19,9 +19,7 @@ class User(Base):
|
||||
hashed_password: Mapped[str] = mapped_column(String(length=1024), nullable=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
TIMESTAMP(timezone=True), index=True, nullable=False, default=datetime.now
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(TIMESTAMP(timezone=True), nullable=False, default=datetime.now)
|
||||
|
||||
user_question_count: Mapped["UserQuestionCount"] = relationship(
|
||||
"UserQuestionCount",
|
||||
@@ -38,6 +36,12 @@ class User(Base):
|
||||
return self.user_question_count.question_count
|
||||
return 0
|
||||
|
||||
@property
|
||||
def last_question_at(self) -> str | None:
|
||||
if self.user_question_count:
|
||||
return self.user_question_count.last_question_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def build(
|
||||
cls,
|
||||
@@ -70,9 +74,7 @@ class AccessToken(Base):
|
||||
|
||||
user_id = mapped_column(INTEGER, ForeignKey("users.id", ondelete="cascade"), nullable=False)
|
||||
token: Mapped[str] = mapped_column(String(length=42), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
TIMESTAMP(timezone=True), index=True, nullable=False, default=datetime.now
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(TIMESTAMP(timezone=True), nullable=False, default=datetime.now)
|
||||
|
||||
user: Mapped["User"] = relationship(
|
||||
"User",
|
||||
@@ -94,3 +96,4 @@ class UserQuestionCount(Base):
|
||||
|
||||
user_id: Mapped[int] = mapped_column(INTEGER, ForeignKey("users.id", ondelete="cascade"), primary_key=True)
|
||||
question_count: Mapped[int] = mapped_column(INTEGER, default=0, nullable=False)
|
||||
last_question_at: Mapped[datetime] = mapped_column(TIMESTAMP(timezone=True), nullable=False, default=datetime.now)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.dialects.sqlite import insert
|
||||
from sqlalchemy.orm import load_only
|
||||
|
||||
@@ -69,7 +69,8 @@ class UserRepository:
|
||||
UserQuestionCount.get_real_column_name(
|
||||
UserQuestionCount.question_count.key
|
||||
): UserQuestionCount.question_count
|
||||
+ 1
|
||||
+ 1,
|
||||
UserQuestionCount.get_real_column_name(UserQuestionCount.last_question_at.key): func.now(),
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user