Skip to content

Instantly share code, notes, and snippets.

@rtekie
Created December 27, 2011 15:23
Show Gist options
  • Save rtekie/1523987 to your computer and use it in GitHub Desktop.
Save rtekie/1523987 to your computer and use it in GitHub Desktop.
Migrate tickets from a Trac database to LighthouseApp
# Migrate records from a Trac database to LighthouseApp
require 'rubygems'
require 'sqlite3'
require 'lib/lighthouse.rb' # download from https://github.com/Caged/lighthouse-api
# Connect to Lighthouse API
Lighthouse.account = 'YOUR LIGHTHOUSE ACCOUNT'
Lighthouse.token = 'YOUR LIGHTHOUSE API TOKEN'
project = Lighthouse::Project.find(:all).first
puts "MIGRATING TICKETS TO PROJECT: #{project.name}"
# Connect to database
db = SQLite3::Database.new("trac.db")
# Retrieve open trac ticket records
columns, *rows = db.execute2("select * from ticket t where t.status in ('new', 'assigned') order by t.id")
puts "TICKET TABLE COLUMNS"
(0..columns.length-1).each do |i|
puts "#{i}:#{columns[i]}"
end
# Process ticket records
rows.each do |row|
puts row[0] # trac ticket ID
# Create a new Lighthouse ticket
ticket = Lighthouse::Ticket.new(:project_id => project.id)
ticket.title = row[14] # summary column
ticket.body = row[15] # description column
# Additional data mapings go here
# Get trac ticket changes and append to the Lighthouse ticket
col, *updates = db.execute2("select newvalue from ticket_change where ticket=? and field = 'comment'", row[0])
updates.each do |update|
upd = update[0]
ticket.body << "\n" + upd if !upd.empty?
end
# Display progress
puts ticket.title
puts ticket.body
ticket.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment