OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/db/migrate/013_fill_position.rb

20 lines
581 B

class FillPosition < ActiveRecord::Migration
def self.up
pos = execute "select project_id, max(position) from issues where parent_id is null group by project_id"
pos.each do |row|
project_id = row[0].to_i
position = row[1].to_i
stories = execute "select id from issues where project_id = #{project_id} and parent_id is null and position is null order by created_on"
stories.each do |id|
position += 1
execute "update issues set position = #{position} where id = #{id}"
end
end
end
def self.down
#pass
end
end