"""add ai message log table

Revision ID: afef72766d6f
Revises: 62efb1742d19
Create Date: 2023-06-26 15:39:41.458206+00:00

"""

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

# revision identifiers, used by Alembic.
revision = "afef72766d6f"
down_revision = "62efb1742d19"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "ai_message_logs",
        sa.Column("id", sa.BigInteger(), sa.Identity(always=False, start=1, cycle=True), nullable=False),
        sa.Column("app_id", sa.BigInteger(), nullable=False),
        sa.Column("instance", sa.String(), nullable=False),
        sa.Column(
            "timestamp",
            postgresql.TIMESTAMP(timezone=True, precision=2),
            server_default=sa.text("CURRENT_TIMESTAMP"),
            nullable=False,
        ),
        sa.Column("message", postgresql.JSONB(), nullable=True),
        sa.Column("parameters", postgresql.JSONB(), nullable=True),
        sa.Column("conversation", postgresql.JSONB(), nullable=True),
        sa.Column("context", postgresql.JSONB(), nullable=True),
        sa.Column("response", sa.String(), nullable=True),
        sa.Column("response_raw", sa.String(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_ai_message_logs_app_id"), "ai_message_logs", ["app_id"], unique=False)
    op.create_index(op.f("ix_ai_message_logs_timestamp"), "ai_message_logs", ["timestamp"], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    op.drop_index(op.f("ix_ai_message_logs_timestamp"), table_name="ai_message_logs")
    op.drop_index(op.f("ix_ai_message_logs_app_id"), table_name="ai_message_logs")
    op.drop_table("ai_message_logs")
