YoloFace-BE/alembic/versions/1d50ca81be81_users.py

219 lines
7.3 KiB
Python
Raw Permalink Normal View History

2024-11-04 07:36:52 +00:00
"""users
2024-11-07 06:12:47 +00:00
Revision ID: 1d50ca81be81
2024-11-04 07:36:52 +00:00
Revises:
2024-11-07 06:12:47 +00:00
Create Date: 2024-11-07 13:45:48.829209
2024-11-04 07:36:52 +00:00
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
from fastapi_user_auth.utils.sqltypes import SecretStrType
# revision identifiers, used by Alembic.
2024-11-07 06:12:47 +00:00
revision = "1d50ca81be81"
2024-11-04 07:36:52 +00:00
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"auth_casbin_rule",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("ptype", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("v0", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("v1", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("v2", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("v3", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("v4", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("v5", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"auth_login_history",
sa.Column("create_time", sa.DateTime(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("user_id", sa.Integer(), nullable=True),
sa.Column(
"login_name",
sqlmodel.sql.sqltypes.AutoString(length=20),
nullable=False,
),
sa.Column("ip", sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
sa.Column(
"ip_info",
sqlmodel.sql.sqltypes.AutoString(length=255),
nullable=False,
),
sa.Column(
"client",
sqlmodel.sql.sqltypes.AutoString(length=20),
nullable=False,
),
sa.Column(
"user_agent",
sqlmodel.sql.sqltypes.AutoString(length=400),
nullable=False,
),
sa.Column(
"login_type",
sqlmodel.sql.sqltypes.AutoString(length=20),
nullable=False,
),
sa.Column(
"login_status",
sqlmodel.sql.sqltypes.AutoString(length=20),
nullable=False,
),
sa.Column(
"forwarded_for",
sqlmodel.sql.sqltypes.AutoString(length=60),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_auth_login_history_create_time"),
"auth_login_history",
["create_time"],
unique=False,
)
op.create_table(
"auth_role",
sa.Column("delete_time", sa.DateTime(), nullable=True),
sa.Column(
"update_time",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=True,
),
sa.Column("create_time", sa.DateTime(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("key", sqlmodel.sql.sqltypes.AutoString(length=40), nullable=False),
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(length=40), nullable=False),
sa.Column(
"desc",
sqlmodel.sql.sqltypes.AutoString(length=400),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_auth_role_create_time"),
"auth_role",
["create_time"],
unique=False,
)
op.create_index(op.f("ix_auth_role_key"), "auth_role", ["key"], unique=True)
op.create_index(
op.f("ix_auth_role_update_time"),
"auth_role",
["update_time"],
unique=False,
)
op.create_table(
"auth_token",
sa.Column("create_time", sa.DateTime(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("token", sa.String(length=48), nullable=False),
sa.Column("data", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_auth_token_create_time"),
"auth_token",
["create_time"],
unique=False,
)
op.create_index(op.f("ix_auth_token_token"), "auth_token", ["token"], unique=True)
op.create_table(
"auth_user",
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column(
"password",
SecretStrType(),
nullable=False,
),
sa.Column(
"username",
sqlmodel.sql.sqltypes.AutoString(length=32),
nullable=False,
),
sa.Column("delete_time", sa.DateTime(), nullable=True),
sa.Column(
"update_time",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=True,
),
sa.Column("create_time", sa.DateTime(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column(
"nickname",
sqlmodel.sql.sqltypes.AutoString(length=40),
nullable=True,
),
sa.Column(
"avatar",
sqlmodel.sql.sqltypes.AutoString(length=255),
nullable=True,
),
2024-11-07 06:12:47 +00:00
sa.Column("sex", sqlmodel.sql.sqltypes.AutoString(length=15), nullable=True),
sa.Column(
"real_name",
sqlmodel.sql.sqltypes.AutoString(length=15),
nullable=True,
),
2024-11-04 11:41:15 +00:00
sa.Column("phone", sqlmodel.sql.sqltypes.AutoString(length=15), nullable=True),
2024-11-04 07:36:52 +00:00
sa.Column(
"student_id",
sqlmodel.sql.sqltypes.AutoString(length=15),
nullable=True,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_auth_user_create_time"),
"auth_user",
["create_time"],
unique=False,
)
op.create_index(op.f("ix_auth_user_email"), "auth_user", ["email"], unique=False)
op.create_index(
op.f("ix_auth_user_update_time"),
"auth_user",
["update_time"],
unique=False,
)
op.create_index(
op.f("ix_auth_user_username"), "auth_user", ["username"], unique=True
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_auth_user_username"), table_name="auth_user")
op.drop_index(op.f("ix_auth_user_update_time"), table_name="auth_user")
op.drop_index(op.f("ix_auth_user_email"), table_name="auth_user")
op.drop_index(op.f("ix_auth_user_create_time"), table_name="auth_user")
op.drop_table("auth_user")
op.drop_index(op.f("ix_auth_token_token"), table_name="auth_token")
op.drop_index(op.f("ix_auth_token_create_time"), table_name="auth_token")
op.drop_table("auth_token")
op.drop_index(op.f("ix_auth_role_update_time"), table_name="auth_role")
op.drop_index(op.f("ix_auth_role_key"), table_name="auth_role")
op.drop_index(op.f("ix_auth_role_create_time"), table_name="auth_role")
op.drop_table("auth_role")
op.drop_index(
op.f("ix_auth_login_history_create_time"),
table_name="auth_login_history",
)
op.drop_table("auth_login_history")
op.drop_table("auth_casbin_rule")
# ### end Alembic commands ###