decorate_models_by_relation.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env sentry exec
  2. from __future__ import annotations
  3. from sentry.models.group import Group
  4. from sentry.models.organization import Organization
  5. from sentry.models.project import Project
  6. from sentry.models.release import Release
  7. from sentry.utils.silo.decorate_models_by_relation import (
  8. TargetRelations,
  9. decorate_models_by_relation,
  10. )
  11. """
  12. This is an alternative to add_silo_decorators.py that uses an algorithmic definition of
  13. the silos and aims for 100% coverage. It examines the fields of model classes and
  14. uses a graph traversal algorithm to find all models that point to the `Organization`
  15. model, either directly or through a number of steps. Those models are tagged for the
  16. region silo, and all others for the control silo.
  17. Instructions for use:
  18. 1. Commit or stash any Git changes in progress.
  19. 2. Update foreign key relationships to identify models in the region silo.
  20. 2. From the Sentry project root, do
  21. ./scripts/silo/decorate_models_by_relation.py
  22. 3. Do `git status` or `git diff` to observe the results. Commit if you're happy.
  23. """
  24. REGION_TARGET_RELATIONS = TargetRelations(
  25. # Foreign key relationships
  26. models=[Organization],
  27. naming_conventions={
  28. # Covers BoundedBigIntegerFields used as soft foreign keys
  29. "organization_id": Organization,
  30. "project_id": Project,
  31. "group_id": Group,
  32. "release_id": Release,
  33. },
  34. )
  35. if __name__ == "__main__":
  36. decorate_models_by_relation(target_relations=REGION_TARGET_RELATIONS)