date fx
This commit is contained in:
@@ -28,21 +28,41 @@ depends_on: str | Sequence[str] | None = None
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# Use IF NOT EXISTS — this is a catch-up migration for columns that
|
||||
# may already exist (inserted by out-of-band schema changes).
|
||||
conn = op.get_bind()
|
||||
|
||||
# Add is_multimodal to llm_providers (from 9f8e7d6c5b4a)
|
||||
op.add_column("llm_providers",
|
||||
sa.Column("is_multimodal", sa.Boolean(), nullable=False, server_default="false")
|
||||
)
|
||||
op.alter_column("llm_providers", "is_multimodal", server_default=None)
|
||||
if not _column_exists(conn, "llm_providers", "is_multimodal"):
|
||||
op.add_column("llm_providers",
|
||||
sa.Column("is_multimodal", sa.Boolean(), nullable=False, server_default="false")
|
||||
)
|
||||
op.alter_column("llm_providers", "is_multimodal", server_default=None)
|
||||
|
||||
# Add provider_id to validation_policies (from a7b1c2d3e4f5)
|
||||
op.add_column("validation_policies",
|
||||
sa.Column("provider_id", sa.String(), nullable=True)
|
||||
)
|
||||
if not _column_exists(conn, "validation_policies", "provider_id"):
|
||||
op.add_column("validation_policies",
|
||||
sa.Column("provider_id", sa.String(), nullable=True)
|
||||
)
|
||||
|
||||
# Add policy_id to llm_validation_results (from b1c2d3e4f5a6)
|
||||
op.add_column("llm_validation_results",
|
||||
sa.Column("policy_id", sa.String(), nullable=True, index=True)
|
||||
if not _column_exists(conn, "llm_validation_results", "policy_id"):
|
||||
op.add_column("llm_validation_results",
|
||||
sa.Column("policy_id", sa.String(), nullable=True, index=True)
|
||||
)
|
||||
|
||||
|
||||
def _column_exists(conn, table: str, column: str) -> bool:
|
||||
"""Check if a column exists in the given table."""
|
||||
from sqlalchemy import text
|
||||
result = conn.execute(
|
||||
text(
|
||||
"SELECT 1 FROM information_schema.columns "
|
||||
"WHERE table_name = :table AND column_name = :column"
|
||||
),
|
||||
{"table": table, "column": column},
|
||||
)
|
||||
return result.scalar() is not None
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
|
||||
Reference in New Issue
Block a user