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:
Dmitry Afanasyev
2023-11-28 23:06:26 +03:00
committed by GitHub
parent c80b001740
commit 2359481fb7
17 changed files with 668 additions and 280 deletions

View File

View 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)