models.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import uuid
  2. from django.contrib.postgres.search import SearchVectorField
  3. from django.db import models
  4. from glitchtip.base_models import SoftDeleteModel
  5. from psqlextra.models import PostgresPartitionedModel
  6. from psqlextra.types import PostgresPartitioningMethod
  7. class TransactionGroup(SoftDeleteModel):
  8. transaction = models.CharField(max_length=1024)
  9. project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
  10. op = models.CharField(max_length=255)
  11. method = models.CharField(max_length=255, null=True, blank=True)
  12. search_vector = SearchVectorField(null=True, editable=False)
  13. class Meta:
  14. unique_together = (("transaction", "project", "op", "method"),)
  15. class TransactionEvent(PostgresPartitionedModel):
  16. id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  17. group = models.ForeignKey(TransactionGroup, on_delete=models.CASCADE)
  18. trace_id = models.UUIDField(db_index=True)
  19. timestamp = models.DateTimeField(help_text="Time at which event happened")
  20. duration = models.PositiveIntegerField(db_index=True, help_text="Milliseconds")
  21. data = models.JSONField()
  22. class Meta:
  23. ordering = ["-timestamp"]
  24. class PartitioningMeta:
  25. method = PostgresPartitioningMethod.RANGE
  26. key = ["timestamp"]