Commit d58eb62d authored by Andrew8xx8's avatar Andrew8xx8

Migrations iproved

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