refactor(database): re-structure

This commit is contained in:
MingxuanGame
2025-07-24 21:01:00 +08:00
parent 43404a7d51
commit f8abc7067f
5 changed files with 210 additions and 138 deletions

26
app/database/auth.py Normal file
View File

@@ -0,0 +1,26 @@
# ruff: noqa: I002
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import Column, DateTime
from sqlmodel import Field, Relationship, SQLModel
if TYPE_CHECKING:
from .user import User
class OAuthToken(SQLModel, table=True):
__tablename__ = "oauth_tokens" # pyright: ignore[reportAssignmentType]
id: int | None = Field(default=None, primary_key=True, index=True)
user_id: int = Field(foreign_key="users.id")
access_token: str = Field(max_length=500, unique=True)
refresh_token: str = Field(max_length=500, unique=True)
token_type: str = Field(default="Bearer", max_length=20)
scope: str = Field(default="*", max_length=100)
expires_at: datetime = Field(sa_column=Column(DateTime))
created_at: datetime = Field(
default_factory=datetime.utcnow, sa_column=Column(DateTime)
)
user: "User" = Relationship()