"""make knowledge synchronization automatically publish

Revision ID: 0011_knowledge_auto_publish
Revises: 0010_prompt_history_management
"""

from alembic import op
import sqlalchemy as sa


revision = "0011_knowledge_auto_publish"
down_revision = "0010_prompt_history_management"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Keep the legacy column for backward compatibility while removing manual
    # review from the active workflow and API.
    op.execute("UPDATE sys_knowledge SET review_mode = 'automatic'")
    op.alter_column(
        "sys_knowledge",
        "review_mode",
        existing_type=sa.String(length=30),
        existing_nullable=False,
        server_default="automatic",
    )


def downgrade() -> None:
    op.alter_column(
        "sys_knowledge",
        "review_mode",
        existing_type=sa.String(length=30),
        existing_nullable=False,
        server_default="manual",
    )
