diff options
Diffstat (limited to 'db/post_migrate/20210525075724_clean_up_pending_builds_table.rb')
-rw-r--r-- | db/post_migrate/20210525075724_clean_up_pending_builds_table.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb b/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb new file mode 100644 index 00000000000..c380f15188a --- /dev/null +++ b/db/post_migrate/20210525075724_clean_up_pending_builds_table.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class CleanUpPendingBuildsTable < ActiveRecord::Migration[6.0] + include ::Gitlab::Database::DynamicModelHelpers + + BATCH_SIZE = 1000 + + disable_ddl_transaction! + + def up + return unless Gitlab.dev_or_test_env? || Gitlab.com? + + each_batch_range('ci_pending_builds', of: BATCH_SIZE) do |min, max| + execute <<~SQL + DELETE FROM ci_pending_builds + USING ci_builds + WHERE ci_builds.id = ci_pending_builds.build_id + AND ci_builds.status != 'pending' + AND ci_builds.type = 'Ci::Build' + AND ci_pending_builds.id BETWEEN #{min} AND #{max} + SQL + end + end + + def down + # noop + end +end |