Naive import of posts, still need to set status_message_id on photos
This commit is contained in:
parent
fefc4ba60e
commit
f4465c9d32
3 changed files with 102 additions and 2 deletions
|
|
@ -43,7 +43,7 @@ module DataConversion
|
||||||
process_raw_invitations
|
process_raw_invitations
|
||||||
process_raw_requests
|
process_raw_requests
|
||||||
process_raw_profiles
|
process_raw_profiles
|
||||||
#posts
|
process_raw_posts
|
||||||
#post_visibilities
|
#post_visibilities
|
||||||
#notifications
|
#notifications
|
||||||
end
|
end
|
||||||
|
|
@ -73,6 +73,41 @@ module DataConversion
|
||||||
log "Imported #{User.count} users."
|
log "Imported #{User.count} users."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_raw_posts
|
||||||
|
log "Importing posts to main table..."
|
||||||
|
Post.connection.execute <<-SQL
|
||||||
|
INSERT INTO posts
|
||||||
|
SELECT mongo_posts.id,
|
||||||
|
people.id,
|
||||||
|
mongo_posts.public,
|
||||||
|
mongo_posts.diaspora_handle,
|
||||||
|
mongo_posts.guid,
|
||||||
|
mongo_posts.pending,
|
||||||
|
mongo_posts.type,
|
||||||
|
mongo_posts.message,
|
||||||
|
NULL,
|
||||||
|
mongo_posts.caption,
|
||||||
|
mongo_posts.remote_photo_path,
|
||||||
|
mongo_posts.remote_photo_name,
|
||||||
|
mongo_posts.random_string,
|
||||||
|
mongo_posts.image,
|
||||||
|
mongo_posts.youtube_titles,
|
||||||
|
mongo_posts.created_at,
|
||||||
|
mongo_posts.updated_at,
|
||||||
|
mongo_posts.mongo_id
|
||||||
|
FROM mongo_posts
|
||||||
|
INNER JOIN people ON (people.mongo_id = mongo_posts.person_mongo_id)
|
||||||
|
SQL
|
||||||
|
log "Imported #{Post.count} posts."
|
||||||
|
|
||||||
|
log "Setting Photo -> StatusMessage relation column..."
|
||||||
|
Photo.connection.execute <<-SQL
|
||||||
|
SELECT * FROM posts
|
||||||
|
WHERE posts.type = "Photo"
|
||||||
|
SQL
|
||||||
|
log "Processed #{Photo.count} photos."
|
||||||
|
end
|
||||||
|
|
||||||
def process_raw_aspects
|
def process_raw_aspects
|
||||||
log "Importing aspects to main table..."
|
log "Importing aspects to main table..."
|
||||||
Aspect.connection.execute <<-SQL
|
Aspect.connection.execute <<-SQL
|
||||||
|
|
|
||||||
2
spec/fixtures/data_conversion/posts.csv
vendored
2
spec/fixtures/data_conversion/posts.csv
vendored
|
|
@ -1,7 +1,7 @@
|
||||||
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
|
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,1294692030000,false,1294692030000,,,,,,,4d2b6ebecc8cb43cc2000027,StatusMessage,bob1d2f837@localhost,4d2b6eb6cc8cb43cc200000a,User2 can see this
|
"",false,1294692030000,false,1294692030000,,,,,,,4d2b6ebecc8cb43cc2000027,StatusMessage,bob1d2f837@localhost,4d2b6eb6cc8cb43cc200000a,User2 can see this
|
||||||
"",false,1294692030000,false,1294692030000,,,,,,,4d2b6ebecc8cb43cc2000029,StatusMessage,bob3c6c46f@localhost,4d2b6eb7cc8cb43cc2000017,User3 can see this
|
"",false,1294692030000,false,1294692030000,,,,,,,4d2b6ebecc8cb43cc2000029,StatusMessage,bob3c6c46f@localhost,4d2b6eb7cc8cb43cc2000017,User3 can see this
|
||||||
,false,1294692032000,false,1294692033000,,,,,mUKUIxkYlV,,4d2b6ebfcc8cb43cc200002d,Photo,bob2f66ee4@localhost,4d2b6eb7cc8cb43cc200000e,
|
,false,1294692032000,false,1294692033000,4d2b6ebecc8cb43cc2000027,,,,mUKUIxkYlV,,4d2b6ebfcc8cb43cc200002d,Photo,bob2f66ee4@localhost,4d2b6eb7cc8cb43cc200000e,
|
||||||
,false,1294692034000,false,1294692034000,,,,,AtwSOhcrt0,,4d2b6ec1cc8cb43cc200002f,Photo,bob3c6c46f@localhost,4d2b6eb7cc8cb43cc2000017,
|
,false,1294692034000,false,1294692034000,,,,,AtwSOhcrt0,,4d2b6ec1cc8cb43cc200002f,Photo,bob3c6c46f@localhost,4d2b6eb7cc8cb43cc2000017,
|
||||||
,false,1294692036000,false,1294692036000,,,/uploads/images,3jcOyI5M444d2b6ec2cc8cb43cc2000036.png,,,4d2b6ec2cc8cb43cc2000036,Photo,bob5aa0fd5@localhost,4d2b6ec2cc8cb43cc2000034,
|
,false,1294692036000,false,1294692036000,,,/uploads/images,3jcOyI5M444d2b6ec2cc8cb43cc2000036.png,,,4d2b6ec2cc8cb43cc2000036,Photo,bob5aa0fd5@localhost,4d2b6ec2cc8cb43cc2000034,
|
||||||
"",false,1294692036000,false,1294692036000,,,,,,,4d2b6ec4cc8cb43cc2000037,StatusMessage,bob5aa0fd5@localhost,4d2b6ec2cc8cb43cc2000034,from another server!
|
"",false,1294692036000,false,1294692036000,,,,,,,4d2b6ec4cc8cb43cc2000037,StatusMessage,bob5aa0fd5@localhost,4d2b6ec2cc8cb43cc2000034,from another server!
|
||||||
|
|
|
||||||
|
|
|
@ -334,6 +334,71 @@ describe DataConversion::ImportToMysql do
|
||||||
profile.person_id.should == Person.where(:mongo_id => profile.mongo_id).first.id
|
profile.person_id.should == Person.where(:mongo_id => profile.mongo_id).first.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe "posts" do
|
||||||
|
before do
|
||||||
|
copy_fixture_for("users")
|
||||||
|
@migrator.import_raw_users
|
||||||
|
@migrator.process_raw_users
|
||||||
|
copy_fixture_for("people")
|
||||||
|
@migrator.import_raw_people
|
||||||
|
@migrator.process_raw_people
|
||||||
|
copy_fixture_for("posts")
|
||||||
|
@migrator.import_raw_posts
|
||||||
|
end
|
||||||
|
|
||||||
|
it "imports data into the posts table" do
|
||||||
|
Mongo::Post.count.should == 6
|
||||||
|
Post.count.should == 0
|
||||||
|
@migrator.process_raw_posts
|
||||||
|
Post.count.should == 6
|
||||||
|
end
|
||||||
|
|
||||||
|
it "imports all the columns" do
|
||||||
|
@migrator.process_raw_posts
|
||||||
|
post = StatusMessage.first
|
||||||
|
mongo_post = Mongo::Post.where(:mongo_id => post.mongo_id).first
|
||||||
|
post.youtube_titles.should be_nil
|
||||||
|
post.pending.should == false
|
||||||
|
post.public.should == false
|
||||||
|
post.status_message_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 == "4d2b6ebecc8cb43cc2000027"
|
||||||
|
post.guid.should == post.mongo_id
|
||||||
|
post.person_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
|
||||||
|
post.diaspora_handle.should == post.person.diaspora_handle
|
||||||
|
post.message.should == "User2 can see this"
|
||||||
|
post.created_at.should == mongo_post.created_at
|
||||||
|
post.updated_at.should == mongo_post.updated_at
|
||||||
|
end
|
||||||
|
|
||||||
|
it "imports the columns of a photo" do
|
||||||
|
@migrator.process_raw_posts
|
||||||
|
post = Photo.first
|
||||||
|
mongo_post = Mongo::Post.where(:mongo_id => post.mongo_id).first
|
||||||
|
post.youtube_titles.should be_nil
|
||||||
|
post.pending.should == false
|
||||||
|
post.public.should == false
|
||||||
|
post.status_message_id.should == StatusMessage.where(:mongo_id => mongo_post.status_message_mongo_id).first.id
|
||||||
|
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 == "4d2b6ebfcc8cb43cc200002d"
|
||||||
|
post.guid.should == post.mongo_id
|
||||||
|
post.person_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
|
||||||
|
post.diaspora_handle.should post.person.diaspora_handle
|
||||||
|
post.message.should be_nil
|
||||||
|
# puts post.created_at.utc? # == true
|
||||||
|
post.created_at.utc.to_i.should == 1294692032 # got 1294663230- minus 8 hours
|
||||||
|
post.updated_at.to_i.should == 1294692033
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
describe "#import_raw" do
|
describe "#import_raw" do
|
||||||
describe "aspects" do
|
describe "aspects" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue