Person#owner_mongo_id should be null if the csv has an empty string

This commit is contained in:
Raphael 2011-01-06 14:16:05 -08:00
parent f4d176011d
commit a1419b9dc0
5 changed files with 61 additions and 3 deletions

View file

@ -9,7 +9,7 @@ module Mongo
class Contact < ActiveRecord::Base; end
#class Invitation < ActiveRecord::Base; end
#class Notification < ActiveRecord::Base; end
#class Person < ActiveRecord::Base; end
class Person < ActiveRecord::Base; end
#Photo?
#Post?
class PostVisibility < ActiveRecord::Base; end

View file

@ -37,8 +37,21 @@ class CreateImportTables < ActiveRecord::Migration
t.boolean :pending, :default => true
t.timestamps
end
add_index :mongo_contacts, [:user_mongo_id, :pending]
add_index :mongo_contacts, [:person_mongo_id, :pending]
create_table :mongo_people do |t|
t.string :mongo_id
t.string :guid
t.text :url
t.string :diaspora_handle
t.text :serialized_public_key
t.string :owner_mongo_id
t.timestamps
end
add_index :mongo_people, :guid, :unique => true
add_index :mongo_people, :owner_mongo_id, :unique => true
add_index :mongo_people, :diaspora_handle, :unique => true
create_table :mongo_post_visibilities do |t|
t.string :aspect_mongo_id

View file

@ -118,6 +118,21 @@ ActiveRecord::Schema.define(:version => 20110105051803) do
add_index "mongo_contacts", ["person_mongo_id", "pending"], :name => "index_mongo_contacts_on_person_mongo_id_and_pending"
add_index "mongo_contacts", ["user_mongo_id", "pending"], :name => "index_mongo_contacts_on_user_mongo_id_and_pending"
create_table "mongo_people", :force => true do |t|
t.string "mongo_id"
t.string "guid"
t.text "url"
t.string "diaspora_handle"
t.text "serialized_public_key"
t.string "owner_mongo_id"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "mongo_people", ["diaspora_handle"], :name => "index_mongo_people_on_diaspora_handle", :unique => true
add_index "mongo_people", ["guid"], :name => "index_mongo_people_on_guid", :unique => true
add_index "mongo_people", ["owner_mongo_id"], :name => "index_mongo_people_on_owner_mongo_id", :unique => true
create_table "mongo_post_visibilities", :force => true do |t|
t.string "aspect_mongo_id"
t.string "post_mongo_id"

View file

@ -105,6 +105,17 @@ module DataConversion
log "Finished. Imported #{Mongo::Request.count} requests."
end
def import_raw_people
log "Loading people file..."
Mongo::Aspect.connection.execute <<-SQL
#{load_string("people")}
#{infile_opts}
(created_at,updated_at,serialized_public_key,url,mongo_id,@owner_mongo_id_var,diaspora_handle)
SET owner_mongo_id = @owner_mongo_id_var
SQL
log "Finished. Imported #{Mongo::Person.count} people."
end
def infile_opts
<<-OPTS
FIELDS TERMINATED BY ','

View file

@ -100,7 +100,26 @@ describe DataConversion::ImportToMysql do
contact.created_at.should be_nil
end
end
describe "people" do
before do
copy_fixture_for("people")
end
it "imports data into the mongo_people table" do
Mongo::Person.count.should == 0
@migrator.import_raw_people
Mongo::Person.count.should == 6
end
it "imports all the columns" do
@migrator.import_raw_people
person = Mongo::Person.first
pp person
person.owner_mongo_id.should be_nil
person.mongo_id.should == "4d26212bcc8cb44df200000d"
person.created_at.should be_nil
end
end
describe "post_visibilities" do
before do
copy_fixture_for("post_visibilities")