agent_0001_initial.py 630 B

1234567891011121314151617181920212223242526
  1. """创建 Agent 库基础表。"""
  2. from alembic import op
  3. from app.infrastructure.mysql.agent_models import AgentBase
  4. revision = "agent_0001"
  5. down_revision = None
  6. branch_labels = None
  7. depends_on = None
  8. TABLE_NAMES = ("agent_threads", "agent_messages", "agent_runs")
  9. def upgrade() -> None:
  10. bind = op.get_bind()
  11. for table in AgentBase.metadata.sorted_tables:
  12. if table.name in TABLE_NAMES:
  13. table.create(bind=bind)
  14. def downgrade() -> None:
  15. bind = op.get_bind()
  16. for table in reversed(AgentBase.metadata.sorted_tables):
  17. if table.name in TABLE_NAMES:
  18. table.drop(bind=bind)