print "Migrating bugs"\r
Issue.destroy_all\r
issues_map = {}\r
- MantisBug.find(:all).each do |bug|\r
+ keep_bug_ids = (Issue.count == 0)\r
+ MantisBug.find(:all, :order => 'id ASC').each do |bug|\r
next unless projects_map[bug.project_id] && users_map[bug.reporter_id]\r
i = Issue.new :project_id => projects_map[bug.project_id], \r
:subject => encode(bug.summary),\r
i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?\r
i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS\r
i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)\r
+ i.id = bug.id if keep_bug_ids\r
next unless i.save\r
issues_map[bug.id] = i.id\r
print '.'\r
i.add_watcher(User.find_by_id(users_map[monitor.user_id]))\r
end\r
end\r
+ \r
+ # update issue id sequence if needed (postgresql)\r
+ Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')\r
puts\r
\r
# Bug relationships\r