diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb')
-rw-r--r-- | db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb b/db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb new file mode 100644 index 00000000000..6fc23c742b9 --- /dev/null +++ b/db/post_migrate/20230322085041_remove_user_namespace_records_from_vsa_aggregation.rb @@ -0,0 +1,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 |