"""add_event_log_info

Revision ID: 2bf9f38d9444
Revises: 81e44dd6047a
Create Date: 2024-05-21 23:00:17.468407

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '2bf9f38d9444'
down_revision = '81e44dd6047a'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('event_log', sa.Column('user', sa.INTEGER(), nullable=True))
    op.add_column('event_log', sa.Column('arcade', sa.INTEGER(), nullable=True))
    op.add_column('event_log', sa.Column('machine', sa.INTEGER(), nullable=True))
    op.add_column('event_log', sa.Column('ip', sa.TEXT(length=39), nullable=True))
    op.alter_column('event_log', 'when_logged',
               existing_type=mysql.TIMESTAMP(),
               server_default=sa.text('now()'),
               existing_nullable=False)
    op.create_foreign_key(None, 'event_log', 'machine', ['machine'], ['id'], onupdate='cascade', ondelete='cascade')
    op.create_foreign_key(None, 'event_log', 'arcade', ['arcade'], ['id'], onupdate='cascade', ondelete='cascade')
    op.create_foreign_key(None, 'event_log', 'aime_user', ['user'], ['id'], onupdate='cascade', ondelete='cascade')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'event_log', type_='foreignkey')
    op.drop_constraint(None, 'event_log', type_='foreignkey')
    op.drop_constraint(None, 'event_log', type_='foreignkey')
    op.alter_column('event_log', 'when_logged',
               existing_type=mysql.TIMESTAMP(),
               server_default=sa.text('current_timestamp()'),
               existing_nullable=False)
    op.drop_column('event_log', 'ip')
    op.drop_column('event_log', 'machine')
    op.drop_column('event_log', 'arcade')
    op.drop_column('event_log', 'user')
    # ### end Alembic commands ###
