Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created April 24, 2010 03:28
Show Gist options
  • Save mwlang/377437 to your computer and use it in GitHub Desktop.
Save mwlang/377437 to your computer and use it in GitHub Desktop.
def clone_table(src_db, dest_db, table)
# filter the rows to be exported
dataset = src_db[table]
# truncate if no key_field
unless key_field
puts "truncating #{table}..."
dest_db[table].delete
end
puts "counting records..."
records = dataset.count
puts "exporting #{records} records for #{table.to_s}"
pbar = ProgressBar.new(table.to_s, records)
threads = []
dataset.each_slice(records / 4) do |rows|
threads << Thread.new(table, rows, threads.size) do |table, rows, i|
puts "starting thread #{i} with #{rows.size}"
dest_db = Sequel.connect("jdbc:sqlserver://10.0.1.2:1348;databaseName=Michaels Test Practice", :user => 'admin', :password => 'thisaintit')
rows.each do |values|
dest_db[table].insert(values)
pbar.inc
end
puts "finished thread #{i}"
end
end
threads.each_with_index{|t, i| puts "joining #{i}"; t.join}
pbar.finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment