diff options
Diffstat (limited to 'db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb')
-rw-r--r-- | db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb b/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb new file mode 100644 index 00000000000..5fc5a5b2b6e --- /dev/null +++ b/db/post_migrate/20210406144743_backfill_total_tuple_count_for_batched_migrations.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class BackfillTotalTupleCountForBatchedMigrations < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + return unless should_run? + + Gitlab::Database::BackgroundMigration::BatchedMigration.all.each do |migration| + total_tuple_count = Gitlab::Database::PgClass.for_table(migration.table_name)&.cardinality_estimate + + migration.update(total_tuple_count: total_tuple_count) + end + end + + def down + return unless should_run? + + Gitlab::Database::BackgroundMigration::BatchedMigration.update_all(total_tuple_count: nil) + end + + private + + def should_run? + Gitlab.dev_or_test_env? || Gitlab.com? + end +end |