Commit 19b87fb4 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Requeue projects pending deletion

There have been several bugs in the project deletion service and worker.
Resulting in projects stuck in pending delete state, which limits users
to create projects with the same name, keeps stale records in the
database, and all kinds of other trouble.

This post deployment migration requeues all these projects for deletion,
in the hope that most of these could be removed by the updated code.
parent b60de9c0
---
title: Requeue pending deletion projects
merge_request:
author:
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class RequeuePendingDeleteProjects < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
admin = User.find_by(admin: true)
return unless admin
@offset = 0
loop do
ids = pending_delete_batch
break if ids.rows.count.zero?
args = ids.map { |id| [id['id'], admin.id, {}] }
Sidekiq::Client.push_bulk('class' => ProjectDestroyWorker, 'args' => args)
@offset += 1
end
end
def down
# noop
end
private
def pending_delete_batch
connection.exec_query(find_batch)
end
BATCH_SIZE = 5000
def find_batch
projects = Arel::Table.new(:projects)
projects.project(projects[:id]).
where(projects[:pending_delete].eq(true)).
skip(@offset * BATCH_SIZE).
take(BATCH_SIZE).
to_sql
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment