2017-01-04 10:02:28 -05:00
|
|
|
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
|
|
|
# for more information on how to write migrations for GitLab.
|
|
|
|
|
2018-11-13 02:27:31 -05:00
|
|
|
class RequeuePendingDeleteProjects < ActiveRecord::Migration[4.2]
|
2017-01-04 10:02:28 -05:00
|
|
|
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, {}] }
|
|
|
|
|
2017-01-12 07:01:41 -05:00
|
|
|
Sidekiq::Client.push_bulk('class' => "ProjectDestroyWorker", 'args' => args)
|
2017-01-04 10:02:28 -05:00
|
|
|
|
|
|
|
@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)
|
2017-06-21 09:48:12 -04:00
|
|
|
projects.project(projects[:id])
|
|
|
|
.where(projects[:pending_delete].eq(true))
|
|
|
|
.where(projects[:namespace_id].not_eq(nil))
|
|
|
|
.skip(@offset * BATCH_SIZE)
|
|
|
|
.take(BATCH_SIZE)
|
|
|
|
.to_sql
|
2017-01-04 10:02:28 -05:00
|
|
|
end
|
|
|
|
end
|