Commit 54957d69 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'rs-fix-migrations' into 'master'

Use raw SQL instead of Rails models in migrations where appropriate

Closes #14694.

See merge request !3429
parents f4238634 47a539df
class ConvertClosedToStateInIssue < ActiveRecord::Migration
include Gitlab::Database
def up
Issue.transaction do
Issue.where(closed: true).update_all(state: :closed)
Issue.where(closed: false).update_all(state: :opened)
end
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
execute "UPDATE #{table_name} SET state = 'opened' WHERE closed = #{false_value}"
end
def down
Issue.transaction do
Issue.where(state: :closed).update_all(closed: true)
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'closed'"
end
private
def table_name
Issue.table_name
end
end
class ConvertClosedToStateInMergeRequest < ActiveRecord::Migration
include Gitlab::Database
def up
MergeRequest.transaction do
MergeRequest.where(closed: true, merged: true).update_all(state: :merged)
MergeRequest.where(closed: true, merged: false).update_all(state: :closed)
MergeRequest.where(closed: false).update_all(state: :opened)
end
execute "UPDATE #{table_name} SET state = 'merged' WHERE closed = #{true_value} AND merged = #{true_value}"
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value} AND merged = #{false_value}"
execute "UPDATE #{table_name} SET state = 'opened' WHERE closed = #{false_value}"
end
def down
MergeRequest.transaction do
MergeRequest.where(state: :closed).update_all(closed: true)
MergeRequest.where(state: :merged).update_all(closed: true, merged: true)
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'closed'"
execute "UPDATE #{table_name} SET closed = #{true_value}, merged = #{true_value} WHERE state = 'merged'"
end
private
def table_name
MergeRequest.table_name
end
end
class ConvertClosedToStateInMilestone < ActiveRecord::Migration
include Gitlab::Database
def up
Milestone.transaction do
Milestone.where(closed: true).update_all(state: :closed)
Milestone.where(closed: false).update_all(state: :active)
end
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
execute "UPDATE #{table_name} SET state = 'active' WHERE closed = #{false_value}"
end
def down
Milestone.transaction do
Milestone.where(state: :closed).update_all(closed: true)
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'cloesd'"
end
private
def table_name
Milestone.table_name
end
end
class ConvertMergeStatusInMergeRequest < ActiveRecord::Migration
def up
MergeRequest.transaction do
MergeRequest.where(merge_status: 1).update_all("new_merge_status = 'unchecked'")
MergeRequest.where(merge_status: 2).update_all("new_merge_status = 'can_be_merged'")
MergeRequest.where(merge_status: 3).update_all("new_merge_status = 'cannot_be_merged'")
end
execute "UPDATE #{table_name} SET new_merge_status = 'unchecked' WHERE merge_status = 1"
execute "UPDATE #{table_name} SET new_merge_status = 'can_be_merged' WHERE merge_status = 2"
execute "UPDATE #{table_name} SET new_merge_status = 'cannot_be_merged' WHERE merge_status = 3"
end
def down
MergeRequest.transaction do
MergeRequest.where(new_merge_status: :unchecked).update_all("merge_status = 1")
MergeRequest.where(new_merge_status: :can_be_merged).update_all("merge_status = 2")
MergeRequest.where(new_merge_status: :cannot_be_merged).update_all("merge_status = 3")
execute "UPDATE #{table_name} SET merge_status = 1 WHERE new_merge_status = 'unchecked'"
execute "UPDATE #{table_name} SET merge_status = 2 WHERE new_merge_status = 'can_be_merged'"
execute "UPDATE #{table_name} SET merge_status = 3 WHERE new_merge_status = 'cannot_be_merged'"
end
private
def table_name
MergeRequest.table_name
end
end
class AllowMergesForForks < ActiveRecord::Migration
def self.up
add_column :merge_requests, :target_project_id, :integer, :null => true
MergeRequest.update_all("target_project_id = project_id")
execute "UPDATE #{table_name} SET target_project_id = project_id"
change_column :merge_requests, :target_project_id, :integer, :null => false
rename_column :merge_requests, :project_id, :source_project_id
end
......@@ -10,4 +10,10 @@ class AllowMergesForForks < ActiveRecord::Migration
remove_column :merge_requests, :target_project_id
rename_column :merge_requests, :source_project_id,:project_id
end
private
def table_name
MergeRequest.table_name
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment