"""add prompt history metadata and ordering index

Revision ID: 0010_prompt_history_management
Revises: 0009_logs_storage
"""

from alembic import op
import sqlalchemy as sa


revision = "0010_prompt_history_management"
down_revision = "0009_logs_storage"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.add_column(
        "sys_prompt",
        sa.Column("change_type", sa.String(length=20), nullable=False, server_default="save"),
    )
    op.add_column("sys_prompt", sa.Column("source_prompt_id", sa.BigInteger(), nullable=True))
    op.create_index("ix_sys_prompt_updated_at_id", "sys_prompt", ["updated_at", "id"])


def downgrade() -> None:
    op.drop_index("ix_sys_prompt_updated_at_id", table_name="sys_prompt")
    op.drop_column("sys_prompt", "source_prompt_id")
    op.drop_column("sys_prompt", "change_type")
