summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb')
-rw-r--r--db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb b/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb
new file mode 100644
index 00000000000..49c9efc497c
--- /dev/null
+++ b/db/post_migrate/20220204095121_backfill_namespace_statistics_with_dependency_proxy_size.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class BackfillNamespaceStatisticsWithDependencyProxySize < Gitlab::Database::Migration[1.0]
+ DELAY_INTERVAL = 2.minutes.to_i
+ BATCH_SIZE = 500
+ MIGRATION = 'PopulateNamespaceStatistics'
+
+ disable_ddl_transaction!
+
+ def up
+ groups = exec_query <<~SQL
+ SELECT dependency_proxy_manifests.group_id FROM dependency_proxy_manifests
+ UNION
+ SELECT dependency_proxy_blobs.group_id from dependency_proxy_blobs
+ SQL
+
+ groups.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |group_ids, index|
+ migrate_in(index * DELAY_INTERVAL, MIGRATION, [group_ids, [:dependency_proxy_size]])
+ end
+ end
+
+ def down
+ # no-op
+ end
+end