summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-05-02 13:59:18 +0200
committerToon Claes <toon@gitlab.com>2017-05-10 15:01:27 +0200
commit1af540122563c372c03668f36e6a2123bff94222 (patch)
tree9e4774b63a625d475c0797d05cd11a3adf127200 /db
parent09c2aab4aa4661b147545e2c41b6a0100fc57b11 (diff)
downloadgitlab-ce-1af540122563c372c03668f36e6a2123bff94222.tar.gz
Add post-deploy migrate to cleanup projects in pending delete state
There are many projects in `pending_delete` state, this post-deploy migration cleans them up. The script is based on https://gitlab.com/gitlab-org/gitlab-ce/snippets/1648654 and https://gitlab.com/gitlab-org/gitlab-ce/snippets/1611429. The use of these scripts were described in https://gitlab.com/gitlab-com/infrastructure/issues/888.
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170502101023_clean_up_pending_delete_projects.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/db/post_migrate/20170502101023_clean_up_pending_delete_projects.rb b/db/post_migrate/20170502101023_clean_up_pending_delete_projects.rb
new file mode 100644
index 00000000000..52c7c160ea2
--- /dev/null
+++ b/db/post_migrate/20170502101023_clean_up_pending_delete_projects.rb
@@ -0,0 +1,47 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class CleanUpPendingDeleteProjects < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ admin = User.find_by(admin: true)
+ return unless admin
+
+ Project.unscoped.where(pending_delete: true).each { |project| delete_project(project, admin) }
+ end
+
+ def down
+ # noop
+ end
+
+ private
+
+ def delete_project(project, user)
+ project.team.truncate
+
+ unlink_fork(project) if project.forked?
+
+ [:events, :issues, :merge_requests, :labels, :milestones, :notes, :snippets].each do |thing|
+ project.send(thing).delete_all
+ end
+
+ # Override Project#remove_pages for this instance so it doesn't do anything
+ def project.remove_pages
+ end
+
+ project.destroy!
+ end
+
+ def unlink_fork(project)
+ merge_requests = project.forked_from_project.merge_requests.opened.from_project(project)
+
+ merge_requests.update_all(state: 'closed')
+
+ project.forked_project_link.destroy
+ end
+end