20260423_0005_add_trace_spans.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """add trace spans
  2. Revision ID: 20260423_0005
  3. Revises: 20260423_0004
  4. Create Date: 2026-04-23 18:00:00
  5. """
  6. from collections.abc import Sequence
  7. from alembic import op
  8. import sqlalchemy as sa
  9. revision: str = "20260423_0005"
  10. down_revision: str | None = "20260423_0004"
  11. branch_labels: Sequence[str] | None = None
  12. depends_on: Sequence[str] | None = None
  13. def upgrade() -> None:
  14. op.create_table(
  15. "trace_span",
  16. sa.Column("run_id", sa.String(length=36), nullable=False),
  17. sa.Column("node_run_id", sa.String(length=36), nullable=True),
  18. sa.Column("parent_span_id", sa.String(length=36), nullable=True),
  19. sa.Column("span_type", sa.String(length=64), nullable=False),
  20. sa.Column("name", sa.String(length=128), nullable=False),
  21. sa.Column("status", sa.String(length=32), nullable=False),
  22. sa.Column("started_time", sa.DateTime(), nullable=False),
  23. sa.Column("ended_time", sa.DateTime(), nullable=True),
  24. sa.Column("duration_ms", sa.Integer(), nullable=True),
  25. sa.Column("attributes_json", sa.JSON(), nullable=True),
  26. sa.Column("error_code", sa.String(length=64), nullable=True),
  27. sa.Column("error_message", sa.Text(), nullable=True),
  28. sa.Column("id", sa.String(length=36), nullable=False),
  29. sa.Column("tenant_id", sa.String(length=36), nullable=False),
  30. sa.Column("created_by", sa.String(length=36), nullable=True),
  31. sa.Column("updated_by", sa.String(length=36), nullable=True),
  32. sa.Column("created_time", sa.DateTime(), nullable=False),
  33. sa.Column("updated_time", sa.DateTime(), nullable=False),
  34. sa.Column("deleted_time", sa.DateTime(), nullable=True),
  35. sa.Column("version", sa.Integer(), nullable=False),
  36. sa.PrimaryKeyConstraint("id"),
  37. )
  38. op.create_index("ix_trace_span_run_id", "trace_span", ["run_id"], unique=False)
  39. op.create_index("ix_trace_span_node_run_id", "trace_span", ["node_run_id"], unique=False)
  40. op.create_index("ix_trace_span_parent_span_id", "trace_span", ["parent_span_id"], unique=False)
  41. op.create_index("ix_trace_span_span_type", "trace_span", ["span_type"], unique=False)
  42. op.create_index("ix_trace_span_status", "trace_span", ["status"], unique=False)
  43. op.create_index("ix_trace_span_tenant_id", "trace_span", ["tenant_id"], unique=False)
  44. def downgrade() -> None:
  45. op.drop_index("ix_trace_span_tenant_id", table_name="trace_span")
  46. op.drop_index("ix_trace_span_status", table_name="trace_span")
  47. op.drop_index("ix_trace_span_span_type", table_name="trace_span")
  48. op.drop_index("ix_trace_span_parent_span_id", table_name="trace_span")
  49. op.drop_index("ix_trace_span_node_run_id", table_name="trace_span")
  50. op.drop_index("ix_trace_span_run_id", table_name="trace_span")
  51. op.drop_table("trace_span")