Update d103d442dc24_add_password_reset_table.py
This commit is contained in:
@@ -24,31 +24,58 @@ depends_on: str | Sequence[str] | None = None
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table("password_resets",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||
sa.Column("reset_code", sqlmodel.sql.sqltypes.AutoString(length=8), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("is_used", sa.Boolean(), nullable=False),
|
||||
sa.Column("used_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("ip_address", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.Column("user_agent", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["lazer_users.id"], ),
|
||||
sa.PrimaryKeyConstraint("id")
|
||||
)
|
||||
op.create_index(op.f("ix_password_resets_email"), "password_resets", ["email"], unique=False)
|
||||
op.create_index(op.f("ix_password_resets_user_id"), "password_resets", ["user_id"], unique=False)
|
||||
op.drop_index(op.f("ix_two_factor_auth_id"), table_name="two_factor_auth")
|
||||
op.drop_index(op.f("ix_two_factor_auth_user_id"), table_name="two_factor_auth")
|
||||
op.drop_table("two_factor_auth")
|
||||
op.drop_index(op.f("ix_user_ip_history_id"), table_name="user_ip_history")
|
||||
op.drop_index(op.f("ix_user_ip_history_ip_address"), table_name="user_ip_history")
|
||||
op.drop_index(op.f("ix_user_ip_history_user_id"), table_name="user_ip_history")
|
||||
op.drop_table("user_ip_history")
|
||||
op.drop_index(op.f("ix_session_verification_user_id"), table_name="session_verification")
|
||||
op.drop_table("session_verification")
|
||||
|
||||
# 安全创建 password_resets 表(如果不存在)
|
||||
try:
|
||||
op.create_table("password_resets",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("email", sa.String(255), nullable=False),
|
||||
sa.Column("reset_code", sa.String(8), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("is_used", sa.Boolean(), nullable=False),
|
||||
sa.Column("used_at", sa.DateTime(), nullable=True),
|
||||
sa.Column("ip_address", sa.String(255), nullable=True),
|
||||
sa.Column("user_agent", sa.String(255), nullable=True),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["lazer_users.id"], ),
|
||||
sa.PrimaryKeyConstraint("id")
|
||||
)
|
||||
except Exception:
|
||||
# 如果表已存在,继续执行
|
||||
pass
|
||||
|
||||
# 安全创建索引
|
||||
try:
|
||||
op.create_index(op.f("ix_password_resets_email"), "password_resets", ["email"], unique=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
op.create_index(op.f("ix_password_resets_user_id"), "password_resets", ["user_id"], unique=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 安全删除 two_factor_auth 表 - 先删除表(这会自动删除外键约束和索引)
|
||||
try:
|
||||
op.drop_table("two_factor_auth")
|
||||
except Exception:
|
||||
# 如果表不存在,继续执行
|
||||
pass
|
||||
|
||||
# 安全删除 user_ip_history 表
|
||||
try:
|
||||
op.drop_table("user_ip_history")
|
||||
except Exception:
|
||||
# 如果表不存在,继续执行
|
||||
pass
|
||||
|
||||
# 安全删除 session_verification 表
|
||||
try:
|
||||
op.drop_table("session_verification")
|
||||
except Exception:
|
||||
# 如果表不存在,继续执行
|
||||
pass
|
||||
op.alter_column("beatmapsets", "nsfw",
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
nullable=True)
|
||||
@@ -70,7 +97,14 @@ def upgrade() -> None:
|
||||
op.alter_column("beatmapsets", "download_disabled",
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
nullable=True)
|
||||
op.drop_index(op.f("uq_user_achievement"), table_name="lazer_user_achievements")
|
||||
|
||||
# 安全删除索引
|
||||
try:
|
||||
op.drop_index(op.f("uq_user_achievement"), table_name="lazer_user_achievements")
|
||||
except Exception:
|
||||
# 如果索引不存在或有外键约束,继续执行
|
||||
pass
|
||||
|
||||
op.alter_column("scores", "has_replay",
|
||||
existing_type=mysql.TINYINT(display_width=1),
|
||||
nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user