41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""add ai pmo simulation field
|
|
|
|
Revision ID: add_ai_pmo_simulation_field
|
|
Revises: add_ai_pmo_kernel_tables
|
|
Create Date: 2026-03-09
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = "add_ai_pmo_simulation_field"
|
|
down_revision = "add_ai_pmo_kernel_tables"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _table_exists(bind, table_name: str) -> bool:
|
|
return sa.inspect(bind).has_table(table_name)
|
|
|
|
|
|
def _column_exists(bind, table_name: str, column_name: str) -> bool:
|
|
inspector = sa.inspect(bind)
|
|
if not inspector.has_table(table_name):
|
|
return False
|
|
return any(col.get("name") == column_name for col in inspector.get_columns(table_name))
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
if _table_exists(bind, "decision_records") and not _column_exists(bind, "decision_records", "simulation_result"):
|
|
op.add_column("decision_records", sa.Column("simulation_result", sa.JSON(), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
if _table_exists(bind, "decision_records") and _column_exists(bind, "decision_records", "simulation_result"):
|
|
op.drop_column("decision_records", "simulation_result")
|