35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""身份源绑定表 — 第三方身份(github open_id / 手机号 / ...)与 users 账号的映射。
|
|
|
|
插件自有表,建在共享 auth 库(与 users 同库不同表):
|
|
chongming-auth 拥有的 users schema 保持最小不改动,身份源扩展物归插件。
|
|
"""
|
|
from datetime import datetime
|
|
from uuid import uuid4
|
|
|
|
from sqlalchemy import UniqueConstraint, func, Column, DateTime
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
|
|
def _pk() -> str:
|
|
return f"{uuid4()}_{int(datetime.now().timestamp())}"
|
|
|
|
|
|
class IdentityBinding(SQLModel, table=True):
|
|
__tablename__ = "identity_bindings" # type: ignore
|
|
__table_args__ = (
|
|
UniqueConstraint("provider", "provider_uid", name="uq_provider_uid"),
|
|
)
|
|
|
|
id: str = Field(default_factory=_pk, primary_key=True, description="绑定记录ID")
|
|
user_id: str = Field(index=True, max_length=255, description="关联的 users.id")
|
|
provider: str = Field(index=True, max_length=32, description="身份源: github / phone / ...")
|
|
provider_uid: str = Field(max_length=255, description="身份源侧唯一标识(github user id / 手机号)")
|
|
created_at: datetime = Field(
|
|
sa_column=Column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
comment="创建时间",
|
|
)
|
|
)
|