Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config

from app.core.audit_log.models import AuditLog
from app.core.config import settings
from app.core.database import Base
from app.services.inventory.models import Product, Reservation
Expand Down
85 changes: 85 additions & 0 deletions migrations/versions/dd775d4f45bb_add_audit_log_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""Add audit log model

Revision ID: dd775d4f45bb
Revises: 8e607d73b2b3
Create Date: 2026-03-16 19:52:54.853052

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'dd775d4f45bb'
down_revision: str | Sequence[str] | None = '8e607d73b2b3'
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(
'audit_logs',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('target_type', sa.String(), nullable=False),
sa.Column('target_id', sa.UUID(), nullable=False),
sa.Column('actor_id', sa.UUID(), nullable=False),
sa.Column('action', sa.String(), nullable=False),
sa.Column('changes', sa.JSON(), nullable=False),
sa.Column(
'created_at',
sa.DateTime(timezone=True),
server_default=sa.text('now()'),
nullable=False,
),
sa.Column('remote_ip', sa.String(length=45), nullable=True),
sa.Column('request_id', sa.String(), nullable=True),
sa.ForeignKeyConstraint(
['actor_id'],
['users.id'],
),
sa.PrimaryKeyConstraint('id'),
)
op.create_index(
op.f('ix_audit_logs_action'), 'audit_logs', ['action'], unique=False
)
op.create_index(
op.f('ix_audit_logs_actor_id'), 'audit_logs', ['actor_id'], unique=False
)
op.create_index(
op.f('ix_audit_logs_created_at'), 'audit_logs', ['created_at'], unique=False
)
op.create_index(
op.f('ix_audit_logs_remote_ip'), 'audit_logs', ['remote_ip'], unique=False
)
op.create_index(
op.f('ix_audit_logs_request_id'), 'audit_logs', ['request_id'], unique=False
)
op.create_index(
op.f('ix_audit_logs_target_id'), 'audit_logs', ['target_id'], unique=False
)
op.create_index(
op.f('ix_audit_logs_target_type'), 'audit_logs', ['target_type'], unique=False
)
op.create_index(
op.f('ix_products_owner_id'), 'products', ['owner_id'], unique=False
)
# ### end Alembic commands ###


def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_products_owner_id'), table_name='products')
op.drop_index(op.f('ix_audit_logs_target_type'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_target_id'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_request_id'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_remote_ip'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_created_at'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_actor_id'), table_name='audit_logs')
op.drop_index(op.f('ix_audit_logs_action'), table_name='audit_logs')
op.drop_table('audit_logs')
# ### end Alembic commands ###