def delete_team(object_id, continuous=True, **kwargs): from sentry.models import Team, TeamStatus, Project, ProjectStatus try: t = Team.objects.get(id=object_id) except Team.DoesNotExist: return if t.status == TeamStatus.VISIBLE: raise DeleteAborted('Aborting team deletion as status is invalid') if t.status != TeamStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Team, instance=t) t.update(status=TeamStatus.DELETION_IN_PROGRESS) # Delete 1 project at a time since this is expensive by itself for project in Project.objects.filter(team=t).order_by('id')[:1]: logger.info('Removing Project id=%s where team=%s', project.id, t.id) project.update(status=ProjectStatus.DELETION_IN_PROGRESS) delete_project(project.id, continuous=False) if continuous: delete_team.delay(object_id=object_id, countdown=15) return t.delete()
def delete_team(object_id, transaction_id=None, continuous=True, **kwargs): from sentry.models import Team, TeamStatus, Project, ProjectStatus try: t = Team.objects.get(id=object_id) except Team.DoesNotExist: return if t.status == TeamStatus.VISIBLE: raise DeleteAborted('Aborting team deletion as status is invalid') if t.status != TeamStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Team, instance=t) t.update(status=TeamStatus.DELETION_IN_PROGRESS) # Delete 1 project at a time since this is expensive by itself for project in Project.objects.filter(team=t).order_by('id')[:1]: project.update(status=ProjectStatus.DELETION_IN_PROGRESS) delete_project(project.id, transaction_id=transaction_id, continuous=False) if continuous: delete_team.apply_async( kwargs={'object_id': object_id, 'transaction_id': transaction_id}, countdown=15, ) return t_id = t.id t.delete() logger.info('object.delete.executed', extra={ 'object_id': t_id, 'transaction_id': transaction_id, 'model': Team.__name__, })
def delete_organization(object_id, continuous=True, **kwargs): from sentry.models import (Organization, OrganizationMember, OrganizationStatus, Team, TeamStatus) try: o = Organization.objects.get(id=object_id) except Team.DoesNotExist: return if o.status == OrganizationStatus.VISIBLE: raise DeleteAborted( 'Aborting organization deletion as status is invalid') if o.status != OrganizationStatus.DELETION_IN_PROGRESS: o.update(status=OrganizationStatus.DELETION_IN_PROGRESS) pending_delete.send(sender=Organization, instance=o) for team in Team.objects.filter(organization=o).order_by('id')[:1]: logger.info('Removing Team id=%s where organization=%s', team.id, o.id) team.update(status=TeamStatus.DELETION_IN_PROGRESS) delete_team(team.id, continuous=False) if continuous: delete_organization.delay(object_id=object_id, countdown=15) return model_list = (OrganizationMember, ) has_more = delete_objects(model_list, relation={'organization': o}, logger=logger) if has_more: if continuous: delete_organization.delay(object_id=object_id, countdown=15) return o.delete()
def delete_organization(object_id, transaction_id=None, continuous=True, **kwargs): from sentry.models import (Organization, OrganizationMember, OrganizationStatus, Team, TeamStatus, Commit, CommitAuthor, Repository) try: o = Organization.objects.get(id=object_id) except Organization.DoesNotExist: return if o.status == OrganizationStatus.VISIBLE: raise DeleteAborted( 'Aborting organization deletion as status is invalid') if o.status != OrganizationStatus.DELETION_IN_PROGRESS: o.update(status=OrganizationStatus.DELETION_IN_PROGRESS) pending_delete.send(sender=Organization, instance=o) for team in Team.objects.filter(organization=o).order_by('id')[:1]: team.update(status=TeamStatus.DELETION_IN_PROGRESS) delete_team(team.id, transaction_id=transaction_id, continuous=False) if continuous: delete_organization.apply_async( kwargs={ 'object_id': object_id, 'transaction_id': transaction_id }, countdown=15, ) return model_list = (OrganizationMember, Commit, CommitAuthor, Repository) has_more = delete_objects( model_list, transaction_id=transaction_id, relation={'organization_id': o.id}, logger=logger, ) if has_more: if continuous: delete_organization.apply_async( kwargs={ 'object_id': object_id, 'transaction_id': transaction_id }, countdown=15, ) return o_id = o.id o.delete() logger.info('object.delete.executed', extra={ 'object_id': o_id, 'transaction_id': transaction_id, 'model': Organization.__name__, })
def delete_project(object_id, continuous=True, **kwargs): from sentry.models import (Activity, EventMapping, Group, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupMeta, GroupResolution, GroupRuleStatus, GroupSeen, GroupTagKey, GroupTagValue, Project, ProjectKey, ProjectStatus, SavedSearchUserDefault, SavedSearch, TagKey, TagValue, UserReport) try: p = Project.objects.get(id=object_id) except Project.DoesNotExist: return if p.status == ProjectStatus.VISIBLE: raise DeleteAborted('Aborting project deletion as status is invalid') if p.status != ProjectStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Project, instance=p) p.update(status=ProjectStatus.DELETION_IN_PROGRESS) # XXX: remove keys first to prevent additional data from flowing in model_list = (Activity, EventMapping, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupSeen, GroupRuleStatus, GroupTagKey, GroupTagValue, ProjectKey, TagKey, TagValue, SavedSearchUserDefault, SavedSearch, UserReport) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return # TODO(dcramer): no project relation so we cant easily bulk # delete today has_more = delete_objects([GroupMeta, GroupResolution], relation={'group__project': p}, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return has_more = delete_events(relation={'project_id': p.id}, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return model_list = (Group, ) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return p.delete()
def delete_project(object_id, continuous=True, **kwargs): from sentry.models import ( Project, ProjectKey, ProjectStatus, TagKey, TagValue, GroupTagKey, GroupTagValue, Activity, EventMapping, Group, GroupRuleStatus, GroupHash, GroupSeen, ) try: p = Project.objects.get(id=object_id) except Project.DoesNotExist: return if p.status == ProjectStatus.VISIBLE: raise DeleteAborted('Aborting project deletion as status is invalid') if p.status != ProjectStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Project, instance=p) p.update(status=ProjectStatus.DELETION_IN_PROGRESS) # XXX: remove keys first to prevent additional data from flowing in model_list = ( ProjectKey, TagKey, TagValue, GroupTagKey, GroupTagValue, EventMapping, Activity, GroupRuleStatus, GroupHash, GroupSeen, ) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return has_more = delete_events(relation={'project_id': p.id}, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return model_list = (Group, ) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return p.delete()
def delete_project(object_id, transaction_id=None, continuous=True, **kwargs): from sentry.models import ( Activity, EventMapping, EventUser, Group, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupMeta, GroupRelease, GroupResolution, GroupRuleStatus, GroupSeen, GroupSubscription, GroupSnooze, GroupTagKey, GroupTagValue, Project, ProjectBookmark, ProjectKey, ProjectStatus, Release, ReleaseFile, SavedSearchUserDefault, SavedSearch, TagKey, TagValue, UserReport, ReleaseEnvironment, Environment ) try: p = Project.objects.get(id=object_id) except Project.DoesNotExist: return if p.status == ProjectStatus.VISIBLE: raise DeleteAborted('Aborting project deletion as status is invalid') if p.status != ProjectStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Project, instance=p) p.update(status=ProjectStatus.DELETION_IN_PROGRESS) # Immediately revoke keys project_keys = list(ProjectKey.objects.filter(project_id=object_id).values_list('id', flat=True)) ProjectKey.objects.filter(project_id=object_id).delete() for key_id in project_keys: logger.info('object.delete.executed', extra={ 'object_id': key_id, 'transaction_id': transaction_id, 'model': ProjectKey.__name__, }) model_list = ( Activity, EventMapping, EventUser, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupRelease, GroupRuleStatus, GroupSeen, GroupSubscription, GroupTagKey, GroupTagValue, ProjectBookmark, ProjectKey, TagKey, TagValue, SavedSearchUserDefault, SavedSearch, UserReport, ReleaseEnvironment, Environment ) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, transaction_id=transaction_id, logger=logger) if has_more: if continuous: delete_project.apply_async( kwargs={'object_id': object_id, 'transaction_id': transaction_id}, countdown=15, ) return # TODO(dcramer): no project relation so we cant easily bulk # delete today has_more = delete_objects([GroupMeta, GroupResolution, GroupSnooze], relation={'group__project': p}, transaction_id=transaction_id, logger=logger) if has_more: if continuous: delete_project.apply_async( kwargs={'object_id': object_id, 'transaction_id': transaction_id}, countdown=15, ) return has_more = delete_events(relation={'project_id': p.id}, transaction_id=transaction_id, logger=logger) if has_more: if continuous: delete_project.apply_async( kwargs={'object_id': object_id, 'transaction_id': transaction_id}, ) return # Release needs to handle deletes after Group is cleaned up as the foreign # key is protected model_list = (Group, ReleaseFile, Release) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, transaction_id=transaction_id, logger=logger) if has_more: if continuous: delete_project.apply_async( kwargs={'object_id': object_id, 'transaction_id': transaction_id}, countdown=15, ) return p_id = p.id p.delete() logger.info('object.delete.queued', extra={ 'object_id': p_id, 'transaction_id': transaction_id, 'model': Project.__name__, })
def delete_project(object_id, continuous=True, **kwargs): from sentry.models import (Activity, EventMapping, Group, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupMeta, GroupResolution, GroupRuleStatus, GroupSeen, GroupTagKey, GroupTagValue, Project, ProjectBookmark, ProjectKey, ProjectStatus, Release, ReleaseFile, SavedSearchUserDefault, SavedSearch, TagKey, TagValue, UserReport) try: p = Project.objects.get(id=object_id) except Project.DoesNotExist: return if p.status == ProjectStatus.VISIBLE: raise DeleteAborted('Aborting project deletion as status is invalid') if p.status != ProjectStatus.DELETION_IN_PROGRESS: pending_delete.send(sender=Project, instance=p) p.update(status=ProjectStatus.DELETION_IN_PROGRESS) # Immediately revoke keys ProjectKey.objects.filter(project_id=object_id).delete() model_list = (Activity, EventMapping, GroupAssignee, GroupBookmark, GroupEmailThread, GroupHash, GroupSeen, GroupRuleStatus, GroupTagKey, GroupTagValue, ProjectBookmark, ProjectKey, TagKey, TagValue, SavedSearchUserDefault, SavedSearch, UserReport) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return # TODO(dcramer): no project relation so we cant easily bulk # delete today has_more = delete_objects([GroupMeta, GroupResolution], relation={'group__project': p}, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return has_more = delete_events(relation={'project_id': p.id}, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return # Release needs to handle deletes after Group is cleaned up as the foreign # key is protected model_list = (Group, ReleaseFile, Release) for model in model_list: has_more = bulk_delete_objects(model, project_id=p.id, logger=logger) if has_more: if continuous: delete_project.delay(object_id=object_id, countdown=15) return p.delete()