Commit d58eb62d authored by Andrew8xx8's avatar Andrew8xx8

Migrations iproved

parent e5f048f4
class ConvertClosedToStateInIssue < ActiveRecord::Migration class ConvertClosedToStateInIssue < ActiveRecord::Migration
def up def up
Issue.transaction do Issue.transaction do
Issue.find_each do |issue| Issue.where(closed: true).update_all("state = 'closed'")
issue.state = issue.closed? ? :closed : :opened Issue.where(closed: false).update_all("state = 'opened'")
issue.save
end
end end
end end
def down def down
Issue.transaction do Issue.transaction do
Issue.find_each do |issue| Issue.where(state: :closed).update_all("closed = 1")
issue.closed = issue.closed?
issue.save
end
end end
end end
end end
class ConvertClosedToStateInMergeRequest < ActiveRecord::Migration class ConvertClosedToStateInMergeRequest < ActiveRecord::Migration
def up def up
MergeRequest.transaction do MergeRequest.transaction do
MergeRequest.find_each do |mr| MergeRequest.where("closed = 1 AND merged = 1").update_all("state = 'merged'")
if mr.closed? && mr.merged? MergeRequest.where("closed = 1 AND merged = 0").update_all("state = 'closed'")
mr.state = :merged MergeRequest.where("closed = 0").update_all("state = 'opened'")
else
if mr.closed?
mr.state = :closed
else
mr.state = :opened
end
end
mr.save
end
end end
end end
def down def down
MergeRequest.transaction do MergeRequest.transaction do
MergeRequest.find_each do |mr| MergeRequest.where(state: :closed).update_all("closed = 1")
mr.closed = mr.closed? || mr.merged? MergeRequest.where(state: :merged).update_all("closed = 1, merged = 1")
mr.closed = mr.merged?
mr.save
end
end end
end end
end end
class ConvertClosedToStateInMilestone < ActiveRecord::Migration class ConvertClosedToStateInMilestone < ActiveRecord::Migration
def up def up
Milestone.transaction do Milestone.transaction do
Milestone.find_each do |milestone| Milestone.where(closed: false).update_all("state = 'opened'")
milestone.state = milestone.closed? ? :closed : :active Milestone.where(closed: false).update_all("state = 'active'")
milestone.save
end
end end
end end
def down def down
Milestone.transaction do Milestone.transaction do
Milestone.find_each do |milestone| Milestone.where(state: :closed).update_all("closed = 1")
milestone.closed = milestone.closed?
milestone.save
end
end end
end end
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