Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20231127185328_fix_broken_user_achievements_revoked.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 548a85b88140bbc918b2c434241e8784aeb220d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

class FixBrokenUserAchievementsRevoked < Gitlab::Database::Migration[2.2]
  disable_ddl_transaction!
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  milestone '16.7'

  class User < MigrationRecord
    self.table_name = 'users'
  end

  def up
    User.reset_column_information

    ghost_id = User.where(user_type: 5).first&.id

    return unless ghost_id

    update_column_in_batches(:user_achievements, :revoked_by_user_id, ghost_id) do |table, query|
      query.where(table[:revoked_at].not_eq(nil)).where(table[:revoked_by_user_id].eq(nil))
    end
  end

  def down
    # noop -- this is a data migration and can't be reversed
  end
end