Files
classifieds/migrations/versions/74911acb8bfa_phase6_admin_foundation_audit_logs_.py
T
nngo 2e9025fe55 06/16 Phase 6 foundation: admin blueprint, audit log, user management
Adds the admin backend foundation: AuditLog + Setting models/migration,
an admin-only dashboard with KPI cards, and user management (search,
ban/suspend/activate, tier override, trust adjust) with audit logging
on every write action. Smoke suite extended to 64 checks.
2026-06-16 11:45:00 -04:00

56 lines
2.1 KiB
Python

"""phase6 admin foundation: audit_logs, settings
Revision ID: 74911acb8bfa
Revises: f2d6b231e3e4
Create Date: 2026-06-16 11:31:53.135086
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '74911acb8bfa'
down_revision = 'f2d6b231e3e4'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('settings',
sa.Column('key', sa.String(length=80), nullable=False),
sa.Column('value', sa.JSON(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('key')
)
op.create_table('audit_logs',
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
sa.Column('actor_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=True),
sa.Column('action', sa.String(length=60), nullable=False),
sa.Column('target_type', sa.String(length=40), nullable=False),
sa.Column('target_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=True),
sa.Column('meta', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['actor_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_audit_logs_action'), ['action'], unique=False)
batch_op.create_index(batch_op.f('ix_audit_logs_actor_id'), ['actor_id'], unique=False)
batch_op.create_index(batch_op.f('ix_audit_logs_target_id'), ['target_id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_audit_logs_target_id'))
batch_op.drop_index(batch_op.f('ix_audit_logs_actor_id'))
batch_op.drop_index(batch_op.f('ix_audit_logs_action'))
op.drop_table('audit_logs')
op.drop_table('settings')
# ### end Alembic commands ###