summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorToon Claes <toon@iotcl.com>2017-08-18 10:02:46 +0200
committerToon Claes <toon@iotcl.com>2017-08-22 14:31:40 +0200
commitd4e5ac1bed844210df089862b234ffb0ff3854f7 (patch)
treecee14d82299b2f4ea0bed787dd32a73239ed7d2a /db/post_migrate
parent2074f39a47645b5ea453adfba84247f2fcc4f3c7 (diff)
downloadgitlab-ce-d4e5ac1bed844210df089862b234ffb0ff3854f7.tar.gz
Use EachBatch concern to loop over batchestc-remove-nonexisting-namespace-pending-delete-projects
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb42
1 files changed, 21 insertions, 21 deletions
diff --git a/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb b/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb
index fe88f25827f..3f085c17133 100644
--- a/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb
+++ b/db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb
@@ -8,35 +8,31 @@ class CleanupNonexistingNamespacePendingDeleteProjects < ActiveRecord::Migration
disable_ddl_transaction!
- def up
- @offset = 0
+ class Project < ActiveRecord::Base
+ self.table_name = 'projects'
- loop do
- ids = pending_delete_batch
+ include ::EachBatch
+ end
- break if ids.empty?
+ class Namespace < ActiveRecord::Base
+ self.table_name = 'namespaces'
+ end
- args = ids.map { |id| Array(id) }
+ def up
+ find_projects.each_batch do |batch|
+ args = batch.pluck(:id).map { |id| [id] }
NamespacelessProjectDestroyWorker.bulk_perform_async(args)
-
- @offset += 1
end
end
def down
- # noop
+ # NOOP
end
private
- def pending_delete_batch
- connection.exec_query(find_batch).map { |row| row['id'].to_i }
- end
-
- BATCH_SIZE = 5000
-
- def find_batch
+ def find_projects
projects = Project.arel_table
namespaces = Namespace.arel_table
@@ -44,11 +40,15 @@ class CleanupNonexistingNamespacePendingDeleteProjects < ActiveRecord::Migration
.where(namespaces[:id].eq(projects[:namespace_id]))
.exists.not
- projects.project(projects[:id])
- .where(projects[:pending_delete].eq(true))
+ # SELECT "projects"."id"
+ # FROM "projects"
+ # WHERE "projects"."pending_delete" = 't'
+ # AND (NOT (EXISTS
+ # (SELECT 1
+ # FROM "namespaces"
+ # WHERE "namespaces"."id" = "projects"."namespace_id")))
+ Project.where(projects[:pending_delete].eq(true))
.where(namespace_query)
- .skip(@offset * BATCH_SIZE)
- .take(BATCH_SIZE)
- .to_sql
+ .select(:id)
end
end