Created
April 11, 2011 15:22
-
-
Save NickClark/913689 to your computer and use it in GitHub Desktop.
this would be best optimized as a MYSQL script
This file contains 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
#client is a MYSQL::Client object | |
client.query("SELECT * FROM local_event_attendance").each do |ea| | |
event = Event.find_by_orig_id(table_prefix + ea["eventID"].to_s + current_import_year.year.to_s).try(:id) | |
person = Person.find_by_orig_id(table_prefix + ea["memberID"].to_s).try(:id) | |
Registration.create( | |
:event_id => event, | |
:person_id => person, | |
:created_at => ea["date"], | |
:uniform => ea["uniform"].to_s.downcase == "yes" | |
) | |
end |
This file contains 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
use old_database; | |
INSERT INTO new_database.registrations (created_at, uniform, event_id, person_id) | |
SELECT date AS created_at, attendance.uniform = 'yes' AS uniform, | |
new_database.events.id AS event_id, | |
new_database.people.id AS person_id | |
FROM attendance | |
JOIN new_database.events on new_database.events.orig_id = CONCAT('something', eventID, '2010') | |
JOIN new_database.people on new_database.people.orig_id = CONCAT(memberID, 'something'); |
This file contains 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
//Turns out, I need to normalize the column first. Also, not shown here, orig_id on both events and people need to be added as an index, other wise performance is not really improved. | |
use pathfinders; | |
DROP TEMPORARY TABLE IF EXISTS attendance_tmp; | |
CREATE TEMPORARY TABLE attendance_tmp | |
SELECT date AS created_at, uniform = 'yes' as uniform, CONCAT('', eventID, '2010') as eventID, CONCAT('', memberID) as memberID | |
FROM local_event_attendance; | |
INSERT INTO clubs_development.registrations (created_at, uniform, event_id, person_id) | |
SELECT attendance_tmp.created_at, attendance_tmp.uniform, | |
clubs_development.events.id AS event_id, | |
clubs_development.people.id AS person_id | |
from attendance_tmp | |
join clubs_development.events on clubs_development.events.orig_id = eventID | |
join clubs_development.people on clubs_development.people.orig_id = memberID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment