60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""add qa context workspaces
|
|
|
|
Revision ID: 20260507_add_qa_context_workspaces
|
|
Revises: 20260506_add_execution_runtime_credentials
|
|
Create Date: 2026-05-07
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
try:
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
except Exception: # pragma: no cover
|
|
JSONB = sa.JSON
|
|
|
|
|
|
revision = "20260507_add_qa_context_workspaces"
|
|
down_revision = "20260506_add_execution_runtime_credentials"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _json_type(bind):
|
|
return JSONB() if bind.dialect.name == "postgresql" else sa.JSON()
|
|
|
|
|
|
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:
|
|
if not _table_exists(bind, table_name):
|
|
return False
|
|
return any(column["name"] == column_name for column in sa.inspect(bind).get_columns(table_name))
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
if not _table_exists(bind, "qa_session_states"):
|
|
return
|
|
with op.batch_alter_table("qa_session_states") as batch_op:
|
|
if not _column_exists(bind, "qa_session_states", "active_workspace"):
|
|
batch_op.add_column(sa.Column("active_workspace", _json_type(bind), nullable=True))
|
|
if not _column_exists(bind, "qa_session_states", "context_capsules"):
|
|
batch_op.add_column(sa.Column("context_capsules", _json_type(bind), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
if not _table_exists(bind, "qa_session_states"):
|
|
return
|
|
with op.batch_alter_table("qa_session_states") as batch_op:
|
|
if _column_exists(bind, "qa_session_states", "context_capsules"):
|
|
batch_op.drop_column("context_capsules")
|
|
if _column_exists(bind, "qa_session_states", "active_workspace"):
|
|
batch_op.drop_column("active_workspace")
|
|
|