"""Updated Monitoring Setup

Revision ID: e3c6ff8c22df
Revises: 25588210dab2
Create Date: 2024-09-25 10:05:57.684506

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

# revision identifiers, used by Alembic.
revision = 'e3c6ff8c22df'
down_revision = '25588210dab2'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('business_event_log',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('event_type', sa.String(length=50), nullable=False),
    sa.Column('tenant_id', sa.Integer(), nullable=False),
    sa.Column('trace_id', sa.String(length=50), nullable=False),
    sa.Column('span_id', sa.String(length=50), nullable=False),
    sa.Column('span_name', sa.String(length=50), nullable=False),
    sa.Column('parent_span_id', sa.String(length=50), nullable=False),
    sa.Column('document_version_id', sa.Integer(), nullable=True),
    sa.Column('chat_session_id', sa.Integer(), nullable=True),
    sa.Column('interaction_id', sa.Integer(), nullable=True),
    sa.Column('environment', sa.String(length=20), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    op.drop_table('llm_usage_metric')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    op.create_table('llm_usage_metric',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('tenant_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('environment', sa.VARCHAR(length=20), autoincrement=False, nullable=False),
    sa.Column('activity', sa.VARCHAR(length=20), autoincrement=False, nullable=False),
    sa.Column('sub_activity', sa.VARCHAR(length=20), autoincrement=False, nullable=False),
    sa.Column('activity_detail', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.Column('session_id', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.Column('interaction_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('document_version_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('prompt_tokens', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('completion_tokens', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('total_tokens', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('cost', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('latency', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('model_name', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('timestamp', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('additional_info', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='llm_usage_metric_pkey')
    )
    op.drop_table('business_event_log', schema='public')
    # ### end Alembic commands ###
