Set booleans correctly

This commit is contained in:
Raphael 2011-01-06 15:42:34 -08:00
parent 770e90064d
commit 7668276a99
2 changed files with 19 additions and 9 deletions

View file

@ -5,6 +5,10 @@
module DataConversion module DataConversion
class ImportToMysql < DataConversion::Base class ImportToMysql < DataConversion::Base
def boolean_set(string)
"#{string}= IF(STRCMP(@#{string},'false'), TRUE, FALSE)"
end
def import_raw def import_raw
truncate_tables truncate_tables
import_raw_users import_raw_users
@ -36,10 +40,12 @@ module DataConversion
#{load_string("users")} #{load_string("users")}
#{infile_opts} #{infile_opts}
(mongo_id, username, serialized_private_key, encrypted_password, (mongo_id, username, serialized_private_key, encrypted_password,
invites, invitation_token, invitation_sent_at, getting_started, invites, invitation_token, invitation_sent_at, @getting_started,
disable_mail, language, last_sign_in_ip, @last_sign_in_at_var, @disable_mail, language, last_sign_in_ip, @last_sign_in_at_var,
reset_password_token, password_salt) reset_password_token, password_salt)
SET last_sign_in_at = FROM_UNIXTIME(LEFT(@last_sign_in_at_var, LENGTH(@last_sign_in_at_var)-3)); SET last_sign_in_at = FROM_UNIXTIME(LEFT(@last_sign_in_at_var, LENGTH(@last_sign_in_at_var)-3)),
#{boolean_set("getting_started")},
#{boolean_set("disable_mail")};
SQL SQL
log "Finished. Imported #{Mongo::User.count} users." log "Finished. Imported #{Mongo::User.count} users."
end end
@ -80,7 +86,8 @@ module DataConversion
Mongo::Contact.connection.execute <<-SQL Mongo::Contact.connection.execute <<-SQL
#{load_string("contacts")} #{load_string("contacts")}
#{infile_opts} #{infile_opts}
(mongo_id, user_mongo_id, person_mongo_id, pending, created_at, updated_at) (mongo_id, user_mongo_id, person_mongo_id, @pending, created_at, updated_at)
SET #{boolean_set("pending")};
SQL SQL
log "Finished. Imported #{Mongo::Contact.count} contacts." log "Finished. Imported #{Mongo::Contact.count} contacts."
end end
@ -118,7 +125,8 @@ module DataConversion
Mongo::Notification.connection.execute <<-SQL Mongo::Notification.connection.execute <<-SQL
#{load_string("notifications")} #{load_string("notifications")}
#{infile_opts} #{infile_opts}
(mongo_id,target_mongo_id,target_type,unread) (mongo_id,target_mongo_id,target_type,@unread)
SET #{boolean_set("unread")};
SQL SQL
log "Finished. Imported #{Mongo::Notification.count} notifications." log "Finished. Imported #{Mongo::Notification.count} notifications."
end end
@ -138,8 +146,10 @@ module DataConversion
Mongo::Profile.connection.execute <<-SQL Mongo::Profile.connection.execute <<-SQL
#{load_string("profiles")} #{load_string("profiles")}
#{infile_opts} #{infile_opts}
(image_url_medium,searchable,image_url,person_mongo_id,gender,diaspora_handle,birthday,last_name,bio,image_url_small,first_name) (image_url_medium,@searchable,image_url,person_mongo_id,gender,diaspora_handle,birthday,last_name,bio,image_url_small,first_name)
SET #{boolean_set("searchable")};
SQL SQL
#STRCMP returns 0 if the arguments are the same
log "Finished. Imported #{Mongo::Profile.count} profiles." log "Finished. Imported #{Mongo::Profile.count} profiles."
end end
def infile_opts def infile_opts

View file

@ -205,8 +205,8 @@ describe DataConversion::ImportToMysql do
profile.person_mongo_id.should == "4d262129cc8cb44df2000001" profile.person_mongo_id.should == "4d262129cc8cb44df2000001"
profile.gender.should == '' profile.gender.should == ''
profile.diaspora_handle.should == '' profile.diaspora_handle.should == ''
profile.birthday.should == '' profile.birthday.should be_nil
profile.last_name.should == 'weinstein' profile.last_name.should == 'weinstien'
profile.bio.should == '' profile.bio.should == ''
profile.image_url_small.should == '' profile.image_url_small.should == ''
profile.first_name.should == 'eugene' profile.first_name.should == 'eugene'
@ -253,7 +253,7 @@ describe DataConversion::ImportToMysql do
bob.invites.should == 4 bob.invites.should == 4
bob.invitation_token.should == "" bob.invitation_token.should == ""
bob.invitation_sent_at.should be_nil bob.invitation_sent_at.should be_nil
bob.getting_started.should be_false bob.getting_started.should be_true
bob.disable_mail.should be_false bob.disable_mail.should be_false
bob.language.should == 'en' bob.language.should == 'en'
bob.last_sign_in_ip.should == '' bob.last_sign_in_ip.should == ''