mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2026-02-03 11:40:39 +03:00
add auth context (#62)
* add user table and superuser creation * add gpt-4-stream-aivvm provider * rename user migration to auth migration
This commit is contained in:
0
bot_microservice/core/auth/__init__.py
Normal file
0
bot_microservice/core/auth/__init__.py
Normal file
0
bot_microservice/core/auth/models/__init__.py
Normal file
0
bot_microservice/core/auth/models/__init__.py
Normal file
22
bot_microservice/core/auth/models/users.py
Normal file
22
bot_microservice/core/auth/models/users.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from fastapi_users_db_sqlalchemy import SQLAlchemyBaseUserTable
|
||||
from fastapi_users_db_sqlalchemy.access_token import SQLAlchemyBaseAccessTokenTable
|
||||
from sqlalchemy import INTEGER, VARCHAR, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, declared_attr, mapped_column
|
||||
|
||||
from infra.database.base import Base
|
||||
|
||||
|
||||
class User(SQLAlchemyBaseUserTable[Mapped[int]], Base):
|
||||
__tablename__ = "users" # type: ignore[assignment]
|
||||
|
||||
id: Mapped[int] = mapped_column(INTEGER, primary_key=True)
|
||||
email: Mapped[str] = mapped_column(VARCHAR(length=320), unique=True, nullable=True) # type: ignore[assignment]
|
||||
username: Mapped[str] = mapped_column(VARCHAR(length=32), unique=True, index=True, nullable=False)
|
||||
|
||||
|
||||
class AccessToken(SQLAlchemyBaseAccessTokenTable[Mapped[int]], Base):
|
||||
__tablename__ = "access_token" # type: ignore[assignment]
|
||||
|
||||
@declared_attr
|
||||
def user_id(cls) -> Mapped[int]:
|
||||
return mapped_column(INTEGER, ForeignKey("users.id", ondelete="cascade"), nullable=False)
|
||||
Reference in New Issue
Block a user