def setup_deletions(self, tagvalue_model, grouptagkey_model, grouptagvalue_model, eventtag_model): from sentry.deletions import default_manager as deletion_manager from sentry.deletions.defaults import BulkModelDeletionTask from sentry.deletions.base import ModelRelation, ModelDeletionTask from sentry.models import Group, Event deletion_manager.register(tagvalue_model, BulkModelDeletionTask) deletion_manager.register(grouptagkey_model, BulkModelDeletionTask) deletion_manager.register(grouptagvalue_model, BulkModelDeletionTask) deletion_manager.register(eventtag_model, BulkModelDeletionTask) deletion_manager.add_dependencies(Group, [ lambda instance: ModelRelation(eventtag_model, {'group_id': instance.id}), lambda instance: ModelRelation(grouptagkey_model, {'group_id': instance.id}), lambda instance: ModelRelation(grouptagvalue_model, {'group_id': instance.id}), ]) deletion_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(eventtag_model, { 'event_id__in': [i.id for i in instance_list] }, ModelDeletionTask), ])
def setup_deletions(self, **kwargs): super(LegacyTagStorage, self).setup_deletions(**kwargs) from sentry.deletions import default_manager as deletion_manager from sentry.deletions.base import ModelRelation, ModelDeletionTask from sentry.models import Project class TagKeyDeletionTask(ModelDeletionTask): def get_child_relations(self, instance): # in bulk model_list = (GroupTagValue, GroupTagKey, TagValue) relations = [ ModelRelation(m, { 'project_id': instance.project_id, 'key': instance.key, }) for m in model_list ] return relations def mark_deletion_in_progress(self, instance_list): for instance in instance_list: if instance.status != TagKeyStatus.DELETION_IN_PROGRESS: instance.update(status=TagKeyStatus.DELETION_IN_PROGRESS) deletion_manager.register(TagKey, TagKeyDeletionTask) deletion_manager.add_dependencies(Project, [ lambda instance: ModelRelation(TagKey, {'project_id': instance.id}), lambda instance: ModelRelation(TagValue, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagKey, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, {'project_id': instance.id}), ])
def setup_deletions(self, tagkey_model, tagvalue_model, grouptagkey_model, grouptagvalue_model, eventtag_model): from sentry.deletions import default_manager from sentry.deletions.defaults import BulkModelDeletionTask from sentry.deletions.base import ModelRelation, ModelDeletionTask from sentry.models import Group, Project, Event class TagKeyDeletionTask(ModelDeletionTask): def get_child_relations(self, instance): # in bulk model_list = (grouptagvalue_model, grouptagkey_model, tagvalue_model) relations = [ ModelRelation(m, { 'project_id': instance.project_id, 'key': instance.key, }) for m in model_list ] return relations def mark_deletion_in_progress(self, instance_list): for instance in instance_list: if instance.status != TagKeyStatus.DELETION_IN_PROGRESS: instance.update( status=TagKeyStatus.DELETION_IN_PROGRESS) default_manager.register(tagkey_model, TagKeyDeletionTask) default_manager.register(tagvalue_model, BulkModelDeletionTask) default_manager.register(grouptagkey_model, BulkModelDeletionTask) default_manager.register(grouptagvalue_model, BulkModelDeletionTask) default_manager.register(eventtag_model, BulkModelDeletionTask) default_manager.add_dependencies(Group, [ lambda instance: ModelRelation(eventtag_model, {'group_id': instance.id}), lambda instance: ModelRelation(grouptagkey_model, {'group_id': instance.id}), lambda instance: ModelRelation(grouptagvalue_model, {'group_id': instance.id}), ]) default_manager.add_dependencies(Project, [ lambda instance: ModelRelation(tagkey_model, {'project_id': instance.id}), lambda instance: ModelRelation(tagvalue_model, {'project_id': instance.id}), lambda instance: ModelRelation(grouptagkey_model, {'project_id': instance.id}), lambda instance: ModelRelation(grouptagvalue_model, {'project_id': instance.id}), ]) default_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(eventtag_model, { 'event_id__in': [i.id for i in instance_list] }, ModelDeletionTask), ])
def setup_deletions(self, **kwargs): super(V2TagStorage, self).setup_deletions(**kwargs) from sentry.deletions import default_manager as deletion_manager from sentry.deletions.defaults import BulkModelDeletionTask from sentry.deletions.base import ModelRelation from sentry.models import Project deletion_manager.register(TagKey, BulkModelDeletionTask) deletion_manager.add_dependencies(Project, [ lambda instance: ModelRelation(TagKey, {'project_id': instance.id}), ])
def setup(self): from sentry.deletions import default_manager from sentry.deletions.defaults import BulkModelDeletionTask from sentry.deletions.base import ModelRelation, ModelDeletionTask from sentry.models import Group, Project, Event from sentry.runner.commands import cleanup from sentry.tasks import merge from .deletions import TagKeyDeletionTask default_manager.register(TagKey, TagKeyDeletionTask) default_manager.register(TagValue, BulkModelDeletionTask) default_manager.register(GroupTagKey, BulkModelDeletionTask) default_manager.register(GroupTagValue, BulkModelDeletionTask) default_manager.register(EventTag, BulkModelDeletionTask) default_manager.add_dependencies(Group, [ lambda instance: ModelRelation(EventTag, {'group_id': instance.id} ), lambda instance: ModelRelation(GroupTagKey, {'group_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, {'group_id': instance.id}), ]) default_manager.add_dependencies(Project, [ lambda instance: ModelRelation(TagKey, {'project_id': instance.id} ), lambda instance: ModelRelation(TagValue, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagKey, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, {'project_id': instance.id}), ]) default_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(EventTag, { 'event_id__in': [i.id for i in instance_list] }, ModelDeletionTask), ]) cleanup.EXTRA_BULK_QUERY_DELETES += [ (GroupTagValue, 'last_seen', None), (TagValue, 'last_seen', None), (EventTag, 'date_added', 'date_added'), ] merge.EXTRA_MERGE_MODELS += [ GroupTagValue, GroupTagKey, ]
def setup(self): from sentry.deletions import default_manager from sentry.deletions.defaults import BulkModelDeletionTask from sentry.deletions.base import ModelRelation, ModelDeletionTask from sentry.models import Group, Project, Event from sentry.runner.commands import cleanup from sentry.tasks import merge from .deletions import TagKeyDeletionTask default_manager.register(TagKey, TagKeyDeletionTask) default_manager.register(TagValue, BulkModelDeletionTask) default_manager.register(GroupTagKey, BulkModelDeletionTask) default_manager.register(GroupTagValue, BulkModelDeletionTask) default_manager.register(EventTag, BulkModelDeletionTask) default_manager.add_dependencies(Group, [ lambda instance: ModelRelation(EventTag, {'group_id': instance.id}), lambda instance: ModelRelation(GroupTagKey, {'group_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, {'group_id': instance.id}), ]) default_manager.add_dependencies(Project, [ lambda instance: ModelRelation(TagKey, {'project_id': instance.id}), lambda instance: ModelRelation(TagValue, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagKey, {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, {'project_id': instance.id}), ]) default_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(EventTag, {'event_id__in': [i.id for i in instance_list]}, ModelDeletionTask), ]) cleanup.EXTRA_BULK_QUERY_DELETES += [ (GroupTagValue, 'last_seen', None), (TagValue, 'last_seen', None), (EventTag, 'date_added', 'date_added'), ] merge.EXTRA_MERGE_MODELS += [ GroupTagValue, GroupTagKey, ]
def setup_deletions(self): from sentry.deletions import default_manager as deletion_manager from sentry.deletions.defaults import BulkModelDeletionTask, ModelDeletionTask from sentry.deletions.base import ModelRelation from sentry.models import Event, Group, Project deletion_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation( EventTag, { 'event_id__in': [i.id for i in instance_list], 'project_id': instance_list[0].project_id }, ModelDeletionTask), ]) deletion_manager.register(TagValue, BulkModelDeletionTask) deletion_manager.register(GroupTagKey, BulkModelDeletionTask) deletion_manager.register(GroupTagValue, BulkModelDeletionTask) deletion_manager.register(EventTag, BulkModelDeletionTask) deletion_manager.add_dependencies(Group, [ lambda instance: ModelRelation( EventTag, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), lambda instance: ModelRelation( GroupTagKey, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), lambda instance: ModelRelation( GroupTagValue, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), ]) deletion_manager.add_dependencies(Project, [ lambda instance: ModelRelation(TagKey, query={'project_id': instance.id}), lambda instance: ModelRelation(TagValue, query={'project_id': instance.id}, partition_key= {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagKey, query={'project_id': instance.id}, partition_key= {'project_id': instance.id}), lambda instance: ModelRelation(GroupTagValue, query={'project_id': instance.id}, partition_key= {'project_id': instance.id}), ]) # NOTE: EventTag is handled by cleanup class TagKeyDeletionTask(ModelDeletionTask): def get_child_relations(self, instance): # in bulk model_list = (GroupTagValue, GroupTagKey, TagValue) # required to deal with custom SQL queries and the ORM # in `bulk_delete_objects` key_id_field_name = 'key_id' if ( db.is_postgres() or db.is_mysql()) else '_key_id' relations = [ ModelRelation( m, query={ 'project_id': instance.project_id, key_id_field_name: instance.id, }, partition_key={'project_id': instance.project_id}) for m in model_list ] return relations def mark_deletion_in_progress(self, instance_list): for instance in instance_list: if instance.status != TagKeyStatus.DELETION_IN_PROGRESS: TagKey.objects.filter( id=instance.id, project_id=instance.project_id, ).update(status=TagKeyStatus.DELETION_IN_PROGRESS) deletion_manager.register(TagKey, TagKeyDeletionTask)
def setup_deletions(self): from sentry.deletions import default_manager as deletion_manager from sentry.deletions.defaults import BulkModelDeletionTask, ModelDeletionTask from sentry.deletions.base import ModelRelation from sentry.models import Event, Group, Project deletion_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(models.EventTag, {'event_id__in': [i.id for i in instance_list]}, ModelDeletionTask), ]) deletion_manager.register(models.TagValue, BulkModelDeletionTask) deletion_manager.register(models.GroupTagKey, BulkModelDeletionTask) deletion_manager.register(models.GroupTagValue, BulkModelDeletionTask) deletion_manager.register(models.EventTag, BulkModelDeletionTask) deletion_manager.add_dependencies(Group, [ lambda instance: ModelRelation( models.EventTag, query={ 'group_id': instance.id, }), lambda instance: ModelRelation( models.GroupTagKey, query={ 'group_id': instance.id, }), lambda instance: ModelRelation( models.GroupTagValue, query={ 'group_id': instance.id, }), ]) deletion_manager.add_dependencies(Project, [ lambda instance: ModelRelation(models.TagKey, query={'project_id': instance.id}), lambda instance: ModelRelation(models.TagValue, query={'project_id': instance.id}), lambda instance: ModelRelation(models.GroupTagKey, query={'project_id': instance.id}), lambda instance: ModelRelation(models.GroupTagValue, query={'project_id': instance.id}), ]) class TagKeyDeletionTask(ModelDeletionTask): def get_child_relations(self, instance): # in bulk model_list = (models.GroupTagValue, models.GroupTagKey, models.TagValue) relations = [ ModelRelation(m, { 'project_id': instance.project_id, 'key': instance.key, }) for m in model_list ] return relations def mark_deletion_in_progress(self, instance_list): for instance in instance_list: if instance.status != TagKeyStatus.DELETION_IN_PROGRESS: instance.update(status=TagKeyStatus.DELETION_IN_PROGRESS) deletion_manager.register(models.TagKey, TagKeyDeletionTask)
def setup_deletions(self): from sentry.deletions import default_manager as deletion_manager from sentry.deletions.defaults import BulkModelDeletionTask, ModelDeletionTask from sentry.deletions.base import ModelRelation from sentry.models import Event, Group, Project deletion_manager.add_bulk_dependencies(Event, [ lambda instance_list: ModelRelation(models.EventTag, {'event_id__in': [i.id for i in instance_list], 'project_id': instance_list[0].project_id}, ModelDeletionTask), ]) deletion_manager.register(models.TagValue, BulkModelDeletionTask) deletion_manager.register(models.GroupTagKey, BulkModelDeletionTask) deletion_manager.register(models.GroupTagValue, BulkModelDeletionTask) deletion_manager.register(models.EventTag, BulkModelDeletionTask) deletion_manager.add_dependencies(Group, [ lambda instance: ModelRelation( models.EventTag, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), lambda instance: ModelRelation( models.GroupTagKey, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), lambda instance: ModelRelation( models.GroupTagValue, query={ 'group_id': instance.id, 'project_id': instance.project_id }, partition_key={'project_id': instance.project_id}), ]) deletion_manager.add_dependencies(Project, [ lambda instance: ModelRelation(models.TagKey, query={'project_id': instance.id}), lambda instance: ModelRelation(models.TagValue, query={'project_id': instance.id}, partition_key={'project_id': instance.id}), lambda instance: ModelRelation(models.GroupTagKey, query={'project_id': instance.id}, partition_key={'project_id': instance.id}), lambda instance: ModelRelation(models.GroupTagValue, query={'project_id': instance.id}, partition_key={'project_id': instance.id}), ]) # NOTE: EventTag is handled by cleanup class TagKeyDeletionTask(ModelDeletionTask): def get_child_relations(self, instance): # in bulk model_list = (models.GroupTagValue, models.GroupTagKey, models.TagValue) # required to deal with custom SQL queries and the ORM # in `bulk_delete_objects` key_id_field_name = 'key_id' if (db.is_postgres()) else '_key_id' relations = [ ModelRelation(m, query={ 'project_id': instance.project_id, key_id_field_name: instance.id, }, partition_key={'project_id': instance.project_id}) for m in model_list ] return relations def mark_deletion_in_progress(self, instance_list): for instance in instance_list: if instance.status != TagKeyStatus.DELETION_IN_PROGRESS: models.TagKey.objects.filter( id=instance.id, project_id=instance.project_id, ).update(status=TagKeyStatus.DELETION_IN_PROGRESS) deletion_manager.register(models.TagKey, TagKeyDeletionTask)