20260423_0005_add_trace_spans.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. import sqlalchemy as sa
  8. from alembic import op
  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("created_by", sa.String(length=36), nullable=True),
  30. sa.Column("updated_by", sa.String(length=36), nullable=True),
  31. sa.Column("created_time", sa.DateTime(), nullable=False),
  32. sa.Column("updated_time", sa.DateTime(), nullable=False),
  33. sa.Column("deleted_time", sa.DateTime(), nullable=True),
  34. sa.Column("version", sa.Integer(), nullable=False),
  35. sa.PrimaryKeyConstraint("id"))
  36. op.create_index("ix_trace_span_run_id", "trace_span", ["run_id"], unique=False)
  37. op.create_index("ix_trace_span_node_run_id", "trace_span", ["node_run_id"], unique=False)
  38. op.create_index("ix_trace_span_parent_span_id", "trace_span", ["parent_span_id"], unique=False)
  39. op.create_index("ix_trace_span_span_type", "trace_span", ["span_type"], unique=False)
  40. op.create_index("ix_trace_span_status", "trace_span", ["status"], unique=False)
  41. def downgrade() -> None:
  42. op.drop_index("ix_trace_span_status", table_name="trace_span")
  43. op.drop_index("ix_trace_span_span_type", table_name="trace_span")
  44. op.drop_index("ix_trace_span_parent_span_id", table_name="trace_span")
  45. op.drop_index("ix_trace_span_node_run_id", table_name="trace_span")
  46. op.drop_index("ix_trace_span_run_id", table_name="trace_span")
  47. op.drop_table("trace_span")