Esempio n. 1
0
def repair_callsigns():
    from sentry.utils.query import RangeQuerySetWrapperWithProgressBar, \
        RangeQuerySetWrapper
    from sentry.models.counter import increment_project_counter
    from sentry.models import Organization, Group, Project

    click.echo('Repairing callsigns')

    queryset = Organization.objects.all()

    for org in RangeQuerySetWrapperWithProgressBar(queryset):
        projects = list(org.project_set.all())
        callsigns = get_callsigns(projects)
        for project in projects:
            if project.callsign is None:
                Project.objects.filter(
                    pk=project.id,
                    callsign=None
                ).update(callsign=callsigns[project.id])
            q = Group.objects.filter(
                project=project,
                short_id=None,
            )
            for group in RangeQuerySetWrapper(q):
                with catchable_atomic():
                    pending_short_id = increment_project_counter(
                        project)
                    updated = Group.objects.filter(
                        pk=group.id,
                        short_id=None
                    ).update(short_id=pending_short_id)
                    if updated == 0:
                        raise RollbackLocally()
Esempio n. 2
0
def repair_callsigns():
    from sentry.utils.query import RangeQuerySetWrapperWithProgressBar, \
        RangeQuerySetWrapper
    from sentry.models.counter import increment_project_counter
    from sentry.models import Organization, Group, Project

    click.echo('Repairing callsigns')

    queryset = Organization.objects.all()

    for org in RangeQuerySetWrapperWithProgressBar(queryset):
        projects = list(org.project_set.all())
        callsigns = get_callsigns(projects)
        for project in projects:
            if project.callsign is None:
                Project.objects.filter(
                    pk=project.id,
                    callsign=None).update(callsign=callsigns[project.id])
            q = Group.objects.filter(
                project=project,
                short_id=None,
            )
            for group in RangeQuerySetWrapper(q):
                with catchable_atomic():
                    pending_short_id = increment_project_counter(project)
                    updated = Group.objects.filter(
                        pk=group.id,
                        short_id=None).update(short_id=pending_short_id)
                    if updated == 0:
                        raise RollbackLocally()
Esempio n. 3
0
    def forwards(self, orm):
        from sentry.utils.query import RangeQuerySetWrapperWithProgressBar, \
            RangeQuerySetWrapper
        from sentry.models.counter import increment_project_counter

        db.commit_transaction()

        Organization = orm['sentry.Organization']
        Group = orm['sentry.Group']
        Project = orm['sentry.Project']
        ProjectOption = orm['sentry.ProjectOption']

        queryset = Organization.objects.all()

        for org in RangeQuerySetWrapperWithProgressBar(queryset):
            projects = list(org.project_set.all())
            callsigns = get_callsigns(projects)
            for project in projects:
                if project.callsign is None:
                    Project.objects.filter(
                        pk=project.id,
                        callsign=None
                    ).update(callsign=callsigns[project.id])
                    ProjectOption.objects.filter(
                        project=project,
                        key='sentry:reviewed-callsign'
                    ).delete()
                q = Group.objects.filter(
                    project=project,
                    short_id=None,
                )
                for group in RangeQuerySetWrapper(q):
                    with catchable_atomic():
                        pending_short_id = increment_project_counter(
                            project)
                        updated = Group.objects.filter(
                            pk=group.id,
                            short_id=None
                        ).update(short_id=pending_short_id)
                        if updated == 0:
                            raise RollbackLocally()

        db.start_transaction()