Fix merge_requests.source_project_id migration

We need to make sure merge_requests.source_project_id allows NULL values
_before_ updating rows as otherwise this will lead to a NOT NULL
constraint failing.
This commit is contained in:
Yorick Peterse 2017-11-20 18:00:47 +01:00
parent 7a61a8e09b
commit 17132b99aa
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9

View file

@ -21,15 +21,15 @@ class MergeRequestsSourceProjectIdForeignKey < ActiveRecord::Migration
end
def up
MergeRequest.with_orphaned_source_projects.each_batch(of: 100) do |batch|
batch.update_all(source_project_id: nil)
end
# We need to allow NULL values so we can nullify the column when the source
# project is removed. We _don't_ want to remove the merge request, instead
# the application will keep them but close them.
change_column_null(:merge_requests, :source_project_id, true)
MergeRequest.with_orphaned_source_projects.each_batch(of: 100) do |batch|
batch.update_all(source_project_id: nil)
end
add_concurrent_foreign_key(
:merge_requests,
:projects,