summaryrefslogtreecommitdiff
path: root/db/post_migrate/20171114104051_remove_empty_fork_networks.rb
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-11-17 14:47:42 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-11-17 14:47:48 +0000
commit2686626dbf0479bd829f9f89114ec53704fc5444 (patch)
tree618d3434c3a9f3ceda9a2e4eb865712299bb9ed1 /db/post_migrate/20171114104051_remove_empty_fork_networks.rb
parent9a826fcd31430fcaec95cd31755a5712a9504833 (diff)
parente68ee8af4d981cb7b83fae76c0a94059add495fb (diff)
downloadgitlab-ce-2686626dbf0479bd829f9f89114ec53704fc5444.tar.gz
[ci skip] Merge branch 'master' into 36400-trigger-job36400-trigger-job
* master: (21 commits) Changing OAuth lookup to be case insensitive Delete orphaned fork networks in a migration Delete the fork network when removing the last membership Resolve "Performance issues when loading large number of wiki pages" Exports a couple of project related code as es6 modules Fix go-import meta data when enabled_git_access_protocol is a blank string Add dropdowns documentation Convert migration to populate latest merge request ID into a background migration Set 0.69.0 instead of latest for codeclimate image Fix hashed storage with project transfers to another namespace De-duplicate background migration matchers defined in spec/support/migrations_helpers.rb Update database_debugging.md Update database_debugging.md Move installation of apps higher Change to Google Kubernetes Cluster and add internal links Add Ingress description from official docs Add info on creating your own k8s cluster from the cluster page Add info about the installed apps in the Cluster docs Update HA README.md to clarify GitLab support does not troubleshoot DRBD. Optimise getting the pipeline status of commits ...
Diffstat (limited to 'db/post_migrate/20171114104051_remove_empty_fork_networks.rb')
-rw-r--r--db/post_migrate/20171114104051_remove_empty_fork_networks.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/db/post_migrate/20171114104051_remove_empty_fork_networks.rb b/db/post_migrate/20171114104051_remove_empty_fork_networks.rb
new file mode 100644
index 00000000000..2fe99a1b9c1
--- /dev/null
+++ b/db/post_migrate/20171114104051_remove_empty_fork_networks.rb
@@ -0,0 +1,36 @@
+class RemoveEmptyForkNetworks < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 10_000
+
+ class MigrationForkNetwork < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'fork_networks'
+ end
+
+ class MigrationForkNetworkMembers < ActiveRecord::Base
+ self.table_name = 'fork_network_members'
+ end
+
+ disable_ddl_transaction!
+
+ def up
+ say 'Deleting empty ForkNetworks in batches'
+
+ has_members = MigrationForkNetworkMembers
+ .where('fork_network_members.fork_network_id = fork_networks.id')
+ .select(1)
+ MigrationForkNetwork.where('NOT EXISTS (?)', has_members)
+ .each_batch(of: BATCH_SIZE) do |networks|
+ deleted = networks.delete_all
+
+ say "Deleted #{deleted} rows in batch"
+ end
+ end
+
+ def down
+ # nothing
+ end
+end