Skip to content
Snippets Groups Projects

Remove orphaned merge request approvers from the database

Closed Drew Blessing requested to merge dblessing/gitlab-ee:scrub_merge_approvers into master
1 unresolved thread

My first crack at a migration to remove bad data and finally close https://gitlab.com/gitlab-org/gitlab-ee/issues/1

@ayufan noted that this query may lock the approvers table for too long. He suggests we loop through and do sets of 100 until it's all done. However, I can't make this work in a sane way - mostly due to my own lack of experience here. Rails migration gurus, please help me out and suggest how we can do this.

cc/ @rspeicher @yorickpeterse @DouweM

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Milestone changed to %8.10

  • 100 seems to low. I would go with 1k or 10k. Deletion should quite fast.

  • @dblessing

    until exec_delete("DELETE FROM approvers WHERE id IN (SELECT approvers.id FROM approvers LEFT JOIN users ON users.id=approvers.user_id WHERE users.id IS NULL LIMIT 1000)") == 0
    end
    Edited by Kamil Trzcińśki
  • Douwe Maan Milestone changed to %8.11

    Milestone changed to %8.11

  • Reassigned to @dblessing

  • Drew Blessing Added 1 commit:

    Added 1 commit:

    • 7d98c195 - Remove orphaned merge request approvers from the database
  • Author Maintainer

    @yorickpeterse Does this look OK?

  • Reassigned to @DouweM

  • Drew Blessing Unmarked this merge request as a Work In Progress

    Unmarked this merge request as a Work In Progress

  • Drew Blessing Added 3011 commits:

    Added 3011 commits:

    • 36a00a14...cae1f705 - 3011 commits from branch gitlab-org:master
  • Author Maintainer

    Stupid MySQL adapter :disappointed:

  • 1 # Migration type: online without errors (works on previous version and new one)
    2 class RemoveOrphanedApprovers < ActiveRecord::Migration
    3
    4 # In older versions of GitLab there wasn't a dependent destroy on merge
    5 # approvers. This resulted in some orphaned data. See
    6 # https://gitlab.com/gitlab-org/gitlab-ee/issues/1
    7 def up
    8 until exec_delete('DELETE FROM approvers WHERE id IN (SELECT approvers.id FROM approvers LEFT JOIN users ON users.id=approvers.user_id WHERE users.id IS NULL LIMIT 1000)') == 0
  • Drew Blessing Added 1 commit:

    Added 1 commit:

    • 326ae551 - Remove orphaned merge request approvers from the database
  • Reassigned to @dblessing

  • @dblessing For the sub-query, in the past we have used queries such as:

    DELETE FROM notification_settings
    WHERE user_id = #{uid}
    ...
    AND id != (
      SELECT id FROM (
        SELECT min(id) AS id
        FROM notification_settings
        WHERE user_id = #{uid}
        AND source_type = #{stype}
        AND source_id = #{sid}
      ) min_ids
    )

    Note the sub-select (SELECT id FROM ( ... ) min_ids) in the AND id != ( ... ) chunk.

    Edited by yorickpeterse-staging
  • Douwe Maan Milestone changed to %8.12

    Milestone changed to %8.12

  • @dblessing do we still need this? If so and you'd like someone else to pick this up, let me know!

  • Drew Blessing Added 1 commit:

    Added 1 commit:

    Compare with previous version

  • Drew Blessing Added 6036 commits:

    Added 6036 commits:

    • 326ae551...e09ca533 - 6036 commits from branch gitlab-org:master

    Compare with previous version

  • Rubén Dávila Mentioned in commit 3597ed8d

    Mentioned in commit 3597ed8d

  • closed

  • Please register or sign in to reply
    Loading