Migrations iproved
This commit is contained in:
parent
e5f048f44d
commit
d58eb62d68
3 changed files with 11 additions and 34 deletions
|
@ -1,19 +1,14 @@
|
|||
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
|
||||
|
|
|
@ -1,29 +1,16 @@
|
|||
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
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue