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

20230131194959_remove_invalid_deploy_access_level.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57364e2200ba0a22d972d91528a9d676b8c63315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

class RemoveInvalidDeployAccessLevel < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  # clean up any rows with invalid access_level entries
  def up
    update_column_in_batches(:protected_environment_deploy_access_levels, :access_level, nil) do |table, query|
      query.where(
        table.grouping(table[:user_id].not_eq(nil).or(table[:group_id].not_eq(nil)))
             .and(table[:access_level].not_eq(nil)))
    end
  end

  def down
    # no-op

    # we are setting access_level to NULL if group_id or user_id are present
  end
end