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

20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6fc23c742b918924c38a6fbf71ceec7a13a74701 (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
# frozen_string_literal: true

class RemoveUserNamespaceRecordsFromVsaAggregation < Gitlab::Database::Migration[2.1]
  BATCH_SIZE = 100

  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  def up
    aggregations_model = define_batchable_model('analytics_cycle_analytics_aggregations')
    namespaces_model = define_batchable_model('namespaces')

    aggregations_model.each_batch(of: BATCH_SIZE) do |relation|
      inner_query = namespaces_model
        .where(type: 'Group')
        .where(aggregations_model.arel_table[:group_id].eq(namespaces_model.arel_table[:id]))

      relation.where('NOT EXISTS (?)', inner_query).delete_all
    end
  end

  def down
    # noop
  end
end