2017-09-10 17:25:29 +05:30
|
|
|
# This is the counterpart of RequeuePendingDeleteProjects and cleans all
|
|
|
|
# projects with `pending_delete = true` and that do not have a namespace.
|
2018-12-23 12:14:25 +05:30
|
|
|
class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration[4.2]
|
2017-09-10 17:25:29 +05:30
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
|
|
|
@offset = 0
|
|
|
|
|
|
|
|
loop do
|
|
|
|
ids = pending_delete_batch
|
|
|
|
|
|
|
|
break if ids.empty?
|
|
|
|
|
|
|
|
args = ids.map { |id| Array(id) }
|
|
|
|
|
|
|
|
NamespacelessProjectDestroyWorker.bulk_perform_async(args)
|
|
|
|
|
|
|
|
@offset += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# noop
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def pending_delete_batch
|
2018-03-17 18:26:18 +05:30
|
|
|
connection.exec_query(find_batch).map { |row| row['id'].to_i }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
BATCH_SIZE = 5000
|
|
|
|
|
|
|
|
def find_batch
|
|
|
|
projects = Arel::Table.new(:projects)
|
|
|
|
projects.project(projects[:id])
|
|
|
|
.where(projects[:pending_delete].eq(true))
|
|
|
|
.where(projects[:namespace_id].eq(nil))
|
|
|
|
.skip(@offset * BATCH_SIZE)
|
|
|
|
.take(BATCH_SIZE)
|
|
|
|
.to_sql
|
|
|
|
end
|
|
|
|
end
|