Files
aiagent/backend/alembic/versions/006_add_execution_parent_depth.py

50 lines
1.5 KiB
Python
Raw Normal View History

"""add execution parent/depth columns
Revision ID: 006_add_execution_parent_depth
Revises: 005_persistent_user_memory
Create Date: 2026-04-08
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.mysql import CHAR
revision = "006_add_execution_parent_depth"
down_revision = "005_persistent_user_memory"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"executions",
sa.Column("parent_execution_id", CHAR(36), nullable=True, comment="父执行ID"),
)
op.add_column(
"executions",
sa.Column("depth", sa.Integer(), nullable=False, server_default="0", comment="执行深度根为0"),
)
op.create_foreign_key(
"fk_executions_parent_execution_id",
"executions",
"executions",
["parent_execution_id"],
["id"],
)
op.create_index(
"ix_executions_parent_execution_id",
"executions",
["parent_execution_id"],
unique=False,
)
op.create_index("ix_executions_depth", "executions", ["depth"], unique=False)
op.alter_column("executions", "depth", server_default=None)
def downgrade() -> None:
op.drop_index("ix_executions_depth", table_name="executions")
op.drop_index("ix_executions_parent_execution_id", table_name="executions")
op.drop_constraint("fk_executions_parent_execution_id", "executions", type_="foreignkey")
op.drop_column("executions", "depth")
op.drop_column("executions", "parent_execution_id")