85 lines
4.2 KiB
Python
85 lines
4.2 KiB
Python
"""Fix user login log table name
|
|
|
|
Revision ID: 2dcd04d3f4dc
|
|
Revises: 3eef4794ded1
|
|
Create Date: 2025-08-18 00:07:06.886879
|
|
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import mysql
|
|
import sqlmodel
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "2dcd04d3f4dc"
|
|
down_revision: str | Sequence[str] | None = "3eef4794ded1"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table("user_login_log",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("ip_address", sqlmodel.sql.sqltypes.AutoString(length=45), nullable=False),
|
|
sa.Column("user_agent", sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
|
|
sa.Column("login_time", sa.DateTime(), nullable=False),
|
|
sa.Column("country_code", sqlmodel.sql.sqltypes.AutoString(length=2), nullable=True),
|
|
sa.Column("country_name", sqlmodel.sql.sqltypes.AutoString(length=100), nullable=True),
|
|
sa.Column("city_name", sqlmodel.sql.sqltypes.AutoString(length=100), nullable=True),
|
|
sa.Column("latitude", sqlmodel.sql.sqltypes.AutoString(length=20), nullable=True),
|
|
sa.Column("longitude", sqlmodel.sql.sqltypes.AutoString(length=20), nullable=True),
|
|
sa.Column("time_zone", sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
|
|
sa.Column("asn", sa.Integer(), nullable=True),
|
|
sa.Column("organization", sqlmodel.sql.sqltypes.AutoString(length=200), nullable=True),
|
|
sa.Column("login_success", sa.Boolean(), nullable=False),
|
|
sa.Column("login_method", sqlmodel.sql.sqltypes.AutoString(length=50), nullable=False),
|
|
sa.Column("notes", sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
|
|
sa.PrimaryKeyConstraint("id")
|
|
)
|
|
op.create_index(op.f("ix_user_login_log_ip_address"), "user_login_log", ["ip_address"], unique=False)
|
|
op.create_index(op.f("ix_user_login_log_user_id"), "user_login_log", ["user_id"], unique=False)
|
|
op.drop_index(op.f("ix_userloginlog_ip_address"), table_name="userloginlog")
|
|
op.drop_index(op.f("ix_userloginlog_user_id"), table_name="userloginlog")
|
|
op.drop_table("userloginlog")
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table("userloginlog",
|
|
sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
|
|
sa.Column("user_id", mysql.INTEGER(), autoincrement=False, nullable=False),
|
|
sa.Column("ip_address", mysql.VARCHAR(length=45), nullable=False),
|
|
sa.Column("user_agent", mysql.VARCHAR(length=500), nullable=True),
|
|
sa.Column("login_time", mysql.DATETIME(), nullable=False),
|
|
sa.Column("country_code", mysql.VARCHAR(length=2), nullable=True),
|
|
sa.Column("country_name", mysql.VARCHAR(length=100), nullable=True),
|
|
sa.Column("city_name", mysql.VARCHAR(length=100), nullable=True),
|
|
sa.Column("latitude", mysql.VARCHAR(length=20), nullable=True),
|
|
sa.Column("longitude", mysql.VARCHAR(length=20), nullable=True),
|
|
sa.Column("time_zone", mysql.VARCHAR(length=50), nullable=True),
|
|
sa.Column("asn", mysql.INTEGER(), autoincrement=False, nullable=True),
|
|
sa.Column("organization", mysql.VARCHAR(length=200), nullable=True),
|
|
sa.Column("login_success", mysql.TINYINT(display_width=1), autoincrement=False, nullable=False),
|
|
sa.Column("login_method", mysql.VARCHAR(length=50), nullable=False),
|
|
sa.Column("notes", mysql.VARCHAR(length=500), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
mysql_collate="utf8mb4_0900_ai_ci",
|
|
mysql_default_charset="utf8mb4",
|
|
mysql_engine="InnoDB"
|
|
)
|
|
op.create_index(op.f("ix_userloginlog_user_id"), "userloginlog", ["user_id"], unique=False)
|
|
op.create_index(op.f("ix_userloginlog_ip_address"), "userloginlog", ["ip_address"], unique=False)
|
|
op.drop_index(op.f("ix_user_login_log_user_id"), table_name="user_login_log")
|
|
op.drop_index(op.f("ix_user_login_log_ip_address"), table_name="user_login_log")
|
|
op.drop_table("user_login_log")
|
|
# ### end Alembic commands ###
|