44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""add invites table — dev SPA 邀请码登录改 DB 后端。
|
|
|
|
Revision ID: 0005
|
|
Revises: 0004
|
|
Create Date: 2026-05-19
|
|
|
|
接 05-19 邀请码登录(`/v1/auth/login_invite`):原 `ZCBOT_INVITES` env 字符串解析撤,
|
|
改 `invites` 表。最薄 schema:
|
|
- token PK — login 入口直接查这列
|
|
- name UNIQUE — 推导 uuid5 用,同 name = 同 user_id,UNIQUE 防"两 token 同身份"漏
|
|
- created_at — 审计
|
|
|
|
不存 user_id(由 uuid5(NS, name) 推导,namespace 固定不动);不存 revoked_at
|
|
(撤销直接 DELETE,5 人级别用户不要软删的额外分支)。
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "0005"
|
|
down_revision: Union[str, None] = "0004"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"invites",
|
|
sa.Column("token", sa.Text(), primary_key=True),
|
|
sa.Column("name", sa.Text(), nullable=False, unique=True),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("invites")
|