Files
life-echo/api/alembic/versions/0013_conversations_playground_judge_json.py

40 lines
1.1 KiB
Python
Raw Normal View History

"""Persist Playground GLM conversation judge snapshot on conversations.
Revision ID: 0013_playground_judge
Revises: 0012_mem_fact_tl_lineage
"""
from typing import Sequence, Union
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from alembic import op
revision: str = "0013_playground_judge"
down_revision: Union[str, None] = "0012_mem_fact_tl_lineage"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def _has_column(table: str, column: str) -> bool:
bind = op.get_bind()
return any(c["name"] == column for c in sa.inspect(bind).get_columns(table))
def upgrade() -> None:
if not _has_column("conversations", "playground_conversation_judge_json"):
op.add_column(
"conversations",
sa.Column(
"playground_conversation_judge_json",
postgresql.JSON(astext_type=sa.Text()),
nullable=True,
),
)
def downgrade() -> None:
if _has_column("conversations", "playground_conversation_judge_json"):
op.drop_column("conversations", "playground_conversation_judge_json")