delete-organization-mappings 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. import click
  3. from sentry.runner import configure
  4. configure()
  5. from sentry.models.organizationmapping import OrganizationMapping
  6. from sentry.services.hybrid_cloud.organization import organization_service
  7. from sentry.silo import SiloMode
  8. from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
  9. @click.command()
  10. @click.option("--dry-run", is_flag=True, default=False)
  11. def main(dry_run):
  12. if SiloMode.get_current_mode() != SiloMode.MONOLITH:
  13. click.echo("Can run in monolith mode only")
  14. return
  15. if dry_run:
  16. click.echo("! DRY RUN MODE !")
  17. for mapping in RangeQuerySetWrapperWithProgressBar(OrganizationMapping.objects.all()):
  18. if not mapping.verified or organization_service.get_organization_by_id(
  19. id=mapping.organization_id
  20. ):
  21. continue
  22. if not dry_run:
  23. click.echo(f"Deleting mapping {mapping.id} with slug {mapping.slug}")
  24. mapping.delete()
  25. else:
  26. click.echo(f"Would have deleted mapping {mapping.id} with slug {mapping.slug}")
  27. click.echo("Done!")
  28. if __name__ == "__main__":
  29. main()