"""create_activity_logs_table

Revision ID: 4b0e8e733ae8
Revises: 0137d50192ed
Create Date: 2025-06-17 18:10:33.492946

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4b0e8e733ae8'
down_revision = '0137d50192ed'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('activity_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('patient_id', sa.Integer(), nullable=True),
    sa.Column('action', sa.String(), nullable=False),
    sa.Column('entity_type', sa.String(), nullable=False),
    sa.Column('entity_id', sa.Integer(), nullable=True),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('event_metadata', sa.JSON(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('ip_address', sa.String(), nullable=True),
    sa.Column('user_agent', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['patient_id'], ['patients.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_activity_action', 'activity_logs', ['action'], unique=False)
    op.create_index('idx_activity_entity', 'activity_logs', ['entity_type', 'entity_id'], unique=False)
    op.create_index('idx_activity_patient_timestamp', 'activity_logs', ['patient_id', 'timestamp'], unique=False)
    op.create_index('idx_activity_timestamp', 'activity_logs', ['timestamp'], unique=False)
    op.create_index('idx_activity_user_timestamp', 'activity_logs', ['user_id', 'timestamp'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('idx_activity_user_timestamp', table_name='activity_logs')
    op.drop_index('idx_activity_timestamp', table_name='activity_logs')
    op.drop_index('idx_activity_patient_timestamp', table_name='activity_logs')
    op.drop_index('idx_activity_entity', table_name='activity_logs')
    op.drop_index('idx_activity_action', table_name='activity_logs')
    op.drop_table('activity_logs')
    # ### end Alembic commands ###
