Created
November 24, 2012 19:49
-
-
Save apotema/4141178 to your computer and use it in GitHub Desktop.
Data load
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sequel' | |
DB_MY = Sequel.connect('mysql://root@localhost/wikimapas_legacy') | |
DB_PG = Sequel.connect('postgres://alexandre@localhost/wikimaps_development') | |
categories_mysql = DB_MY[:categories].select{[id, name, created_at, updated_at]} | |
categories_ids = {} | |
categories_mysql.each do |category| | |
# my => pg | |
categories_ids[category[:id]] = DB_PG[:sub_categories].insert category.merge(category_id: DB_PG[:categories].insert(category)) | |
end | |
# def create_subcategory(name) | |
# category = DB_MY[:category].find_by_name(name) | |
# DB_PG[:sub_category].insert({name: category[:name], category_id: category[:id]}) | |
# end | |
locations_mysql = DB_MY[:locations].select{[id, name, lat.as(latitude), lng.as(longitude), description, category_id, creator_id.as(author_id), created_at, updated_at, deleted_at.as(destroyed_at)]} | |
locations_mysql = locations_mysql.map do |loc| | |
loc.merge! sub_category_id: categories_ids[loc[:category_id]] | |
loc.delete(:category_id) | |
loc | |
end | |
locations_ids = {} | |
locations_mysql.each do |location| | |
locations_ids[location[:id]] = DB_PG[:locations].insert location | |
end | |
videos_mysql = DB_MY[:videos].select{[ youtube_id, source_file_name.as(title), location_id, created_at, updated_at ]} | |
videos_mysql = videos_mysql.map do |video| | |
video.merge! owner_type: 'Location', owner_id: locations_ids[video[:location_id]] | |
video.delete(:location_id) | |
video | |
end | |
DB_PG[:videos].insert_multiple videos_mysql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment