2022-03-10 23:13:31 +08:00
|
|
|
"""Create admin audit log
|
|
|
|
|
|
|
|
Revision ID: b500363567e3
|
|
|
|
Revises: 9282e982bc05
|
|
|
|
Create Date: 2022-03-10 15:26:54.538717
|
|
|
|
|
|
|
|
"""
|
|
|
|
import sqlalchemy_utils
|
|
|
|
from alembic import op
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
2022-03-10 23:37:21 +08:00
|
|
|
revision = "b500363567e3"
|
2022-03-14 18:06:30 +08:00
|
|
|
down_revision = "4729b7096d12"
|
2022-03-10 23:13:31 +08:00
|
|
|
branch_labels = None
|
|
|
|
depends_on = None
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
2022-03-11 00:49:30 +08:00
|
|
|
admin_table = op.create_table(
|
2022-03-10 23:37:21 +08:00
|
|
|
"admin_audit_log",
|
|
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
|
|
sa.Column("created_at", sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
|
|
|
|
sa.Column("admin_user_id", sa.Integer, nullable=False),
|
|
|
|
sa.Column("action", sa.Integer, nullable=False),
|
|
|
|
sa.Column("model", sa.String(length=256), nullable=False),
|
2022-03-11 00:32:35 +08:00
|
|
|
sa.Column("model_id", sa.Integer, nullable=True),
|
2022-03-10 23:37:21 +08:00
|
|
|
sa.Column("data", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
2022-03-11 00:49:30 +08:00
|
|
|
sa.Index("admin_audit_log_admin_user_id_idx", 'admin_user_id'),
|
2022-03-10 23:37:21 +08:00
|
|
|
sa.ForeignKeyConstraint(['admin_user_id'], ['users.id'], ondelete='cascade'),
|
|
|
|
sa.PrimaryKeyConstraint("id"),
|
|
|
|
)
|
2022-03-10 23:13:31 +08:00
|
|
|
|
2022-03-11 00:49:30 +08:00
|
|
|
|
2022-03-10 23:13:31 +08:00
|
|
|
def downgrade():
|
2022-03-10 23:37:21 +08:00
|
|
|
op.drop_table("admin_audit_log")
|