Set target_id on notifications

This commit is contained in:
Raphael 2011-01-10 17:30:37 -08:00
parent 30f98aec3c
commit 079151eeea
2 changed files with 16 additions and 3 deletions

View file

@ -286,6 +286,15 @@ module DataConversion
ON (m_n.recipient_mongo_id = users.mongo_id AND m_n.actor_mongo_id = people.mongo_id) ON (m_n.recipient_mongo_id = users.mongo_id AND m_n.actor_mongo_id = people.mongo_id)
SQL SQL
log "Imported #{Notification.count} notifications." log "Imported #{Notification.count} notifications."
{"Request" => "requests", "Comment" => "comments"}.each_pair do |target_type, table_name|
log "Setting target_id on notifications on #{target_type}"
Notification.connection.execute <<-UPDATESQL
UPDATE notifications, #{table_name}, mongo_notifications
SET notifications.target_id = #{table_name}.id
WHERE notifications.mongo_id = mongo_notifications.mongo_id AND #{table_name}.mongo_id = mongo_notifications.target_mongo_id
UPDATESQL
end
log "Done setting target_id"
end end
def import_raw_users def import_raw_users
log "Loading users file..." log "Loading users file..."
@ -429,11 +438,12 @@ module DataConversion
SQL SQL
log "Finished. Imported #{Mongo::Notification.count} notifications." log "Finished. Imported #{Mongo::Notification.count} notifications."
{"new_request" => "Request", {"new_request" => "Request",
"request_accepted" => "Contact", "request_accepted" => "Request",
"comment_on_post" => "Comment", "comment_on_post" => "Comment",
"also_commented" => "Comment"}.each_pair do |key, value| "also_commented" => "Comment"}.each_pair do |key, value|
Mongo::Notification.where(:action => key).update_all(:target_type => value) Mongo::Notification.where(:action => key).update_all(:target_type => value)
end end
log "Notification target types set."
end end
def import_raw_people def import_raw_people
log "Loading people file..." log "Loading people file..."

View file

@ -373,6 +373,8 @@ describe DataConversion::ImportToMysql do
import_and_process("users") import_and_process("users")
import_and_process("people") import_and_process("people")
import_and_process("posts") import_and_process("posts")
import_and_process("aspects")
import_and_process("requests")
copy_fixture_for("notifications") copy_fixture_for("notifications")
@migrator.import_raw_notifications @migrator.import_raw_notifications
end end
@ -389,9 +391,10 @@ describe DataConversion::ImportToMysql do
notification = Notification.first notification = Notification.first
mongo_notification = Mongo::Notification.first mongo_notification = Mongo::Notification.first
notification.mongo_id.should == "4d2b6eb8cc8cb43cc200001f" notification.mongo_id.should == "4d2b6eb8cc8cb43cc200001f"
notification.target.mongo_id.should == mongo_notification.target_mongo_id notification.target_type.should == "Request"
notification.target_type.should == "new_request" notification.action.should == "new_request"
notification.unread.should be_true notification.unread.should be_true
notification.target.mongo_id.should == mongo_notification.target_mongo_id
end end
end end
describe "post_visibilities" do describe "post_visibilities" do