Services need a mongo_id
This commit is contained in:
parent
62486a17b6
commit
9bd2de06ee
5 changed files with 94 additions and 29 deletions
|
|
@ -142,7 +142,9 @@ class CreateImportTables < ActiveRecord::Migration
|
|||
add_index :mongo_requests, :recipient_mongo_id
|
||||
add_index :mongo_requests, [:sender_mongo_id, :recipient_mongo_id]
|
||||
|
||||
add_column(:services, :user_mongo_id, :string)
|
||||
create_table :mongo_services do |t|
|
||||
t.string :mongo_id
|
||||
t.string :type
|
||||
t.string :user_mongo_id
|
||||
t.string :provider
|
||||
|
|
|
|||
|
|
@ -380,6 +380,7 @@ ActiveRecord::Schema.define(:version => 20110105051803) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "mongo_id"
|
||||
t.string "user_mongo_id"
|
||||
end
|
||||
|
||||
add_index "services", ["user_id"], :name => "index_services_on_user_id"
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ module DataConversion
|
|||
:attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id"],
|
||||
:mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id"]},
|
||||
{:name => :services,
|
||||
:attrs => ["type", "user_mongo_id", "provider", "uid", "access_token", "access_secret", "nickname"],
|
||||
:mongo_attrs => ["_type", "user_id", "provider", "uid", "access_token", "access_secret", "nickname"]},
|
||||
:attrs => ["mongo_id", "type", "user_mongo_id", "provider", "uid", "access_token", "access_secret", "nickname"],
|
||||
:mongo_attrs => ["_id" , "_type", "user_id", "provider", "uid", "access_token", "access_secret", "nickname"]},
|
||||
{:name => :users,
|
||||
:attrs => ["mongo_id","email", "username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt"],
|
||||
:mongo_attrs => ["_id" , "email","username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt"]},
|
||||
|
|
|
|||
|
|
@ -66,11 +66,37 @@ module DataConversion
|
|||
log "Importing aspects to main table..."
|
||||
Aspect.connection.execute <<-SQL
|
||||
INSERT INTO aspects
|
||||
SELECT mongo_aspects.id, mongo_aspects.name, users.id, mongo_aspects.created_at, mongo_aspects.updated_at, mongo_aspects.mongo_id, mongo_aspects.user_mongo_id FROM mongo_aspects INNER JOIN users ON (users.mongo_id = mongo_aspects.user_mongo_id)
|
||||
SELECT mongo_aspects.id,
|
||||
mongo_aspects.name,
|
||||
users.id,
|
||||
mongo_aspects.created_at,
|
||||
mongo_aspects.updated_at,
|
||||
mongo_aspects.mongo_id,
|
||||
mongo_aspects.user_mongo_id
|
||||
FROM mongo_aspects INNER JOIN users ON (users.mongo_id = mongo_aspects.user_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Aspect.count} aspects."
|
||||
end
|
||||
|
||||
def process_raw_services
|
||||
log "Importing services to main table..."
|
||||
Service.connection.execute <<-SQL
|
||||
INSERT INTO services
|
||||
SELECT mongo_services.id,
|
||||
mongo_services.type,
|
||||
users.id,
|
||||
mongo_services.provider,
|
||||
mongo_services.uid,
|
||||
mongo_services.access_token,
|
||||
mongo_services.access_secret,
|
||||
mongo_services.nickname,
|
||||
mongo_services.created_at,
|
||||
mongo_services.updated_at,
|
||||
mongo_services.mongo_id,
|
||||
mongo_services.user_mongo_id
|
||||
FROM mongo_services INNER JOIN users ON (users.mongo_id = mongo_services.user_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Service.count} services."
|
||||
end
|
||||
def import_raw_users
|
||||
log "Loading users file..."
|
||||
Mongo::User.connection.execute <<-SQL
|
||||
|
|
@ -156,7 +182,7 @@ module DataConversion
|
|||
Mongo::Service.connection.execute <<-SQL
|
||||
#{load_string("services")}
|
||||
#{infile_opts}
|
||||
(type,user_mongo_id,@provider,@uid,@access_token,@access_secret,@nickname)
|
||||
(mongo_id, type,user_mongo_id,@provider,@uid,@access_token,@access_secret,@nickname)
|
||||
SET #{nil_es("provider")},
|
||||
#{nil_es("uid")},
|
||||
#{nil_es("access_token")},
|
||||
|
|
|
|||
|
|
@ -50,10 +50,14 @@ describe DataConversion::ImportToMysql do
|
|||
bob.reset_password_token.should be_nil
|
||||
bob.password_salt.should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
describe "aspects" do
|
||||
before do
|
||||
copy_fixture_for("aspects")
|
||||
@migrator.import_raw_aspects
|
||||
copy_fixture_for("users")
|
||||
@migrator.import_raw_users
|
||||
@migrator.process_raw_users
|
||||
end
|
||||
it "imports data into the aspects table" do
|
||||
|
|
@ -75,6 +79,38 @@ describe DataConversion::ImportToMysql do
|
|||
aspect.user_id.should == User.where(:mongo_id => aspect.user_mongo_id).first.id
|
||||
end
|
||||
end
|
||||
describe "services" do
|
||||
before do
|
||||
copy_fixture_for("users")
|
||||
@migrator.import_raw_users
|
||||
@migrator.process_raw_users
|
||||
copy_fixture_for("services")
|
||||
@migrator.import_raw_services
|
||||
end
|
||||
|
||||
it "imports data into the services table" do
|
||||
Mongo::Service.count.should == 2
|
||||
Service.count.should == 0
|
||||
@migrator.process_raw_services
|
||||
Service.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_services
|
||||
service = Service.first
|
||||
service.type_before_type_cast.should == "Services::Facebook"
|
||||
service.user_mongo_id.should == "4d2657eacc8cb46033000011"
|
||||
service.provider.should be_nil
|
||||
service.uid.should be_nil
|
||||
service.access_token.should == "yeah"
|
||||
service.access_secret.should be_nil
|
||||
service.nickname.should be_nil
|
||||
end
|
||||
it 'sets the relation column' do
|
||||
@migrator.process_raw_services
|
||||
service = Service.first
|
||||
service.user_id.should == User.where(:mongo_id => service.user_mongo_id).first.id
|
||||
end
|
||||
end
|
||||
end
|
||||
describe "#import_raw" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue