summaryrefslogtreecommitdiff
path: root/db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb')
-rw-r--r--db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb46
1 files changed, 0 insertions, 46 deletions
diff --git a/db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb b/db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb
deleted file mode 100644
index 69f9c181c10..00000000000
--- a/db/migrate/20171114160904_merge_requests_updated_by_id_foreign_key.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# See http://doc.gitlab.com/ce/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class MergeRequestsUpdatedByIdForeignKey < ActiveRecord::Migration[4.2]
- include Gitlab::Database::MigrationHelpers
-
- # Set this constant to true if this migration requires downtime.
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- class MergeRequest < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'merge_requests'
-
- def self.with_orphaned_updaters
- where('NOT EXISTS (SELECT true FROM users WHERE merge_requests.updated_by_id = users.id)')
- .where('updated_by_id IS NOT NULL')
- end
- end
-
- def up
- MergeRequest.with_orphaned_updaters.each_batch(of: 100) do |batch|
- batch.update_all(updated_by_id: nil)
- end
-
- add_concurrent_index(
- :merge_requests,
- :updated_by_id,
- where: 'updated_by_id IS NOT NULL'
- )
-
- add_concurrent_foreign_key(
- :merge_requests,
- :users,
- column: :updated_by_id,
- on_delete: :nullify
- )
- end
-
- def down
- remove_foreign_key_without_error(:merge_requests, column: :updated_by_id)
- remove_concurrent_index(:merge_requests, :updated_by_id)
- end
-end