Started raw post import

This commit is contained in:
Raphael 2011-01-06 17:01:17 -08:00
parent e46b3e6cf3
commit 89a41826c1
7 changed files with 104 additions and 11 deletions

View file

@ -11,7 +11,7 @@ module Mongo
class Notification < ActiveRecord::Base; end
class Person < ActiveRecord::Base; end
#Photo?
#Post?
class Post < ActiveRecord::Base; end
class PostVisibility < ActiveRecord::Base; end
class Profile < ActiveRecord::Base; end
class Request < ActiveRecord::Base; end

View file

@ -53,6 +53,31 @@ class CreateImportTables < ActiveRecord::Migration
add_index :mongo_people, :owner_mongo_id, :unique => true
add_index :mongo_people, :diaspora_handle, :unique => true
create_table :mongo_posts do |t|
t.string :person_mongo_id
t.boolean :public, :default => false
t.string :diaspora_handle
t.string :guid
t.string :mongo_id
t.boolean :pending, :default => false
t.string :type
t.text :message
t.string :status_message_mongo_id
t.text :caption
t.text :remote_photo_path
t.string :remote_photo_name
t.string :random_string
t.string :image #carrierwave's column
t.text :youtube_titles
t.timestamps
end
add_index :mongo_posts, :type
add_index :mongo_posts, :person_mongo_id
add_index :mongo_posts, :guid
create_table :mongo_invitations do |t|
t.string :mongo_id
t.text :message

View file

@ -169,6 +169,30 @@ ActiveRecord::Schema.define(:version => 20110105051803) do
add_index "mongo_post_visibilities", ["aspect_mongo_id"], :name => "index_mongo_post_visibilities_on_aspect_mongo_id"
add_index "mongo_post_visibilities", ["post_mongo_id"], :name => "index_mongo_post_visibilities_on_post_mongo_id"
create_table "mongo_posts", :force => true do |t|
t.string "person_mongo_id"
t.boolean "public", :default => false
t.string "diaspora_handle"
t.string "guid"
t.string "mongo_id"
t.boolean "pending", :default => false
t.string "type"
t.text "message"
t.string "status_message_mongo_id"
t.text "caption"
t.text "remote_photo_path"
t.string "remote_photo_name"
t.string "random_string"
t.string "image"
t.text "youtube_titles"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "mongo_posts", ["guid"], :name => "index_mongo_posts_on_guid"
add_index "mongo_posts", ["person_mongo_id"], :name => "index_mongo_posts_on_person_mongo_id"
add_index "mongo_posts", ["type"], :name => "index_mongo_posts_on_type"
create_table "mongo_profiles", :force => true do |t|
t.string "diaspora_handle"
t.string "first_name"

View file

@ -36,8 +36,8 @@ module DataConversion
:attrs => ["created_at", "updated_at", "serialized_public_key", "url", "mongo_id", "owner_mongo_id", "diaspora_handle"],
:profile_attrs => ["image_url_medium", "searchable", "image_url", "person_mongo_id", "gender", "diaspora_handle", "birthday", "last_name", "bio", "image_url_small", "first_name"]},
{:name => :posts,
:attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_mongo_id", "caption", "remote_photo_path", "random_string", "image", "mongo_id", "type", "diaspora_handle", "person_mongo_id", "message"],
:mongo_attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_id" , "caption", "remote_photo_path", "random_string", "image", "_id" , "_type", "diaspora_handle", "person_id" , "message"]},
:attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_mongo_id", "caption", "remote_photo_path", "remote_photo_name", "random_string", "image", "mongo_id", "type", "diaspora_handle", "person_mongo_id", "message"],
:mongo_attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_id" , "caption", "remote_photo_path", "remote_photo_name", "random_string", "image", "_id" , "_type", "diaspora_handle", "person_id" , "message"]},
{:name => :requests,
:attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id"],
:mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id"]},

View file

@ -80,7 +80,18 @@ module DataConversion
SQL
log "Finished. Imported #{Mongo::Comment.count} comments."
end
def import_raw_posts
log "Loading posts file..."
Mongo::Post.connection.execute <<-SQL
#{load_string("posts")}
#{infile_opts}
(youtube_titles,@pending,created_at,@public,updated_at,status_message_mongo_id,caption,remote_photo_path,remote_photo_name,random_string,image,mongo_id,type,diaspora_handle,person_mongo_id,message)
SET guid = mongo_id,
#{boolean_set("pending")},
#{boolean_set("public")};
SQL
log "Finished. Imported #{Mongo::Post.count} posts."
end
def import_raw_contacts
log "Loading contacts file..."
Mongo::Contact.connection.execute <<-SQL

View file

@ -1,7 +1,7 @@
youtube_titles,pending,created_at,public,updated_at,status_message_mongo_id,caption,remote_photo_path,random_string,image,mongo_id,type,diaspora_handle,person_mongo_id,message
"",false,1294344498000,false,1294344498000,,,,,,4d262132cc8cb44df2000023,StatusMessage,bob178fa79@localhost,4d26212bcc8cb44df2000008,User2 can see this
"",false,1294344498000,false,1294344498000,,,,,,4d262132cc8cb44df2000025,StatusMessage,bob3127b24@localhost,4d26212bcc8cb44df2000014,User3 can see this
,false,1294344499000,false,1294344499000,,,,5SshxW8nvG,,4d262133cc8cb44df200002d,Photo,bob2f2d21a@localhost,4d26212bcc8cb44df200000c,
,false,1294344500000,false,1294344500000,,,,tTiw1Ynzqe,,4d262134cc8cb44df200002f,Photo,bob3127b24@localhost,4d26212bcc8cb44df2000014,
,false,1294344502000,false,1294344502000,,,/uploads/images,,,4d262135cc8cb44df2000036,Photo,bob5ae60b9@localhost,4d262135cc8cb44df2000034,
"",false,1294344502000,false,1294344502000,,,,,,4d262136cc8cb44df2000037,StatusMessage,bob5ae60b9@localhost,4d262135cc8cb44df2000034,from another server!
youtube_titles,pending,created_at,public,updated_at,status_message_mongo_id,caption,remote_photo_path,remote_photo_name,random_string,image,mongo_id,type,diaspora_handle,person_mongo_id,message
"",false,1294358525000,false,1294358525000,,,,,,,4d2657fdcc8cb46033000023,StatusMessage,bob14cbf20@localhost,4d2657e9cc8cb46033000008,User2 can see this
"",false,1294358525000,false,1294358525000,,,,,,,4d2657fdcc8cb46033000025,StatusMessage,bob3bce0e0@localhost,4d2657eacc8cb46033000014,User3 can see this
,false,1294358527000,false,1294358527000,,,,,65ZfafJNL1,,4d2657fecc8cb4603300002d,Photo,bob2f629f3@localhost,4d2657eacc8cb4603300000c,
,false,1294358528000,false,1294358528000,,,,,o1kk1GdJJ8,,4d2657ffcc8cb4603300002f,Photo,bob3bce0e0@localhost,4d2657eacc8cb46033000014,
,false,1294358530000,false,1294358530000,,,/uploads/images,VKuVR3P7cH4d265801cc8cb46033000036.png,,,4d265801cc8cb46033000036,Photo,bob5f4e201@localhost,4d265801cc8cb46033000034,
"",false,1294358530000,false,1294358530000,,,,,,,4d265802cc8cb46033000037,StatusMessage,bob5f4e201@localhost,4d265801cc8cb46033000034,from another server!

1 youtube_titles pending created_at public updated_at status_message_mongo_id caption remote_photo_path remote_photo_name random_string image mongo_id type diaspora_handle person_mongo_id message
2 false 1294344498000 1294358525000 false 1294344498000 1294358525000 4d262132cc8cb44df2000023 4d2657fdcc8cb46033000023 StatusMessage bob178fa79@localhost bob14cbf20@localhost 4d26212bcc8cb44df2000008 4d2657e9cc8cb46033000008 User2 can see this
3 false 1294344498000 1294358525000 false 1294344498000 1294358525000 4d262132cc8cb44df2000025 4d2657fdcc8cb46033000025 StatusMessage bob3127b24@localhost bob3bce0e0@localhost 4d26212bcc8cb44df2000014 4d2657eacc8cb46033000014 User3 can see this
4 false 1294344499000 1294358527000 false 1294344499000 1294358527000 5SshxW8nvG 65ZfafJNL1 4d262133cc8cb44df200002d 4d2657fecc8cb4603300002d Photo bob2f2d21a@localhost bob2f629f3@localhost 4d26212bcc8cb44df200000c 4d2657eacc8cb4603300000c
5 false 1294344500000 1294358528000 false 1294344500000 1294358528000 tTiw1Ynzqe o1kk1GdJJ8 4d262134cc8cb44df200002f 4d2657ffcc8cb4603300002f Photo bob3127b24@localhost bob3bce0e0@localhost 4d26212bcc8cb44df2000014 4d2657eacc8cb46033000014
6 false 1294344502000 1294358530000 false 1294344502000 1294358530000 /uploads/images VKuVR3P7cH4d265801cc8cb46033000036.png 4d262135cc8cb44df2000036 4d265801cc8cb46033000036 Photo bob5ae60b9@localhost bob5f4e201@localhost 4d262135cc8cb44df2000034 4d265801cc8cb46033000034
7 false 1294344502000 1294358530000 false 1294344502000 1294358530000 4d262136cc8cb44df2000037 4d265802cc8cb46033000037 StatusMessage bob5ae60b9@localhost bob5f4e201@localhost 4d262135cc8cb44df2000034 4d265801cc8cb46033000034 from another server!

View file

@ -122,6 +122,39 @@ describe DataConversion::ImportToMysql do
end
end
describe "posts" do
before do
copy_fixture_for("posts")
end
it "imports data into the mongo_posts table" do
Mongo::Post.count.should == 0
@migrator.import_raw_posts
Mongo::Post.count.should == 6
end
it "imports all the columns" do
@migrator.import_raw_posts
post = Mongo::Post.first
post.youtube_titles.should == {}
post.pending.should == false
post.created_at.to_i.should == 1294358525000
post.public.should == false
post.updated_at.to_i.should == 1294358525000
post.status_message_mongo_id.should be_nil
post.caption.should be_nil
post.remote_photo_path.should be_nil
post.remote_photo_name.should be_nil
post.random_string.should be_nil
post.image.should be_nil
post.mongo_id.should == "4d2657fdcc8cb46033000023"
post.guid.should == post.mongo_id
post.type.should == "StatusMessage"
post.diaspora_handle.should == "bob14cbf20@localhost"
post.person_mongo_id.should == "4d2657e9cc8cb46033000008"
post.message.should == "User2 can see this"
end
end
describe "notifications" do
before do
copy_fixture_for("notifications")