diff --git a/app/models/mongo.rb b/app/models/mongo.rb index e29d02fe758e6886feaf27b0895406aefa2d5ccb..704a375325fbeef6911205f2375db1b940de1135 100644 --- a/app/models/mongo.rb +++ b/app/models/mongo.rb @@ -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 diff --git a/db/migrate/20110105051803_create_import_tables.rb b/db/migrate/20110105051803_create_import_tables.rb index 25ff6cabf1f9581dc1a299917a4896c7fb695c6d..595d157bc2926d11133b20c92ba459905b4f4fe5 100644 --- a/db/migrate/20110105051803_create_import_tables.rb +++ b/db/migrate/20110105051803_create_import_tables.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index bbb2d73aa9b6299707f6964330f4fb0f68488b77..3da2136cdee42bafe1d768cae21ef96ddd86fe71 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/lib/data_conversion/base.rb b/lib/data_conversion/base.rb index fd69907ee3710c71e39cd6d543ba9362b5c6644e..671eaaa415258aa0ce7f26670b52ea9d73e9549a 100644 --- a/lib/data_conversion/base.rb +++ b/lib/data_conversion/base.rb @@ -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"]}, diff --git a/lib/data_conversion/import_to_mysql.rb b/lib/data_conversion/import_to_mysql.rb index 5223baead13d76fdefd948c366e7f33fd42f466f..ccc54c1ef53c777038de9c9e3a5e19edf06dc57e 100644 --- a/lib/data_conversion/import_to_mysql.rb +++ b/lib/data_conversion/import_to_mysql.rb @@ -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 diff --git a/spec/fixtures/data_conversion/posts.csv b/spec/fixtures/data_conversion/posts.csv index d96b41fabaa7d58e4d862624800f05cf4120f192..3d17a337c75a62a78aee882e25fa8eb9e250038f 100644 --- a/spec/fixtures/data_conversion/posts.csv +++ b/spec/fixtures/data_conversion/posts.csv @@ -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! diff --git a/spec/lib/data_conversion/import_to_mysql_spec.rb b/spec/lib/data_conversion/import_to_mysql_spec.rb index 4ea665a0320f3a141d9a48b0bddb41def11fea5e..361423918d7a3dbdf9ce86dbcf050e34ccefa125 100644 --- a/spec/lib/data_conversion/import_to_mysql_spec.rb +++ b/spec/lib/data_conversion/import_to_mysql_spec.rb @@ -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")