Begin writing migration from mongo to mysql
This commit is contained in:
parent
0328c1677c
commit
4e44b197c2
2 changed files with 48 additions and 0 deletions
15
lib/mongo_to_mysql.rb
Normal file
15
lib/mongo_to_mysql.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class MongoToMysql
|
||||
def id_sed
|
||||
@id_sed = sed_replace('{\ \"$oid\"\ :\ \(\"[^"]*\"\)\ }')
|
||||
end
|
||||
def date_sed
|
||||
@date_sed = sed_replace('{\ \"$date\"\ :\ \([0-9]*\)\ }')
|
||||
end
|
||||
def sed_replace(regex)
|
||||
"sed 's/#{regex}/\\1/g'"
|
||||
end
|
||||
end
|
||||
33
lib/tasks/migrations.rake
Normal file
33
lib/tasks/migrations.rake
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib/rake_helpers')
|
||||
include RakeHelpers
|
||||
|
||||
namespace :migrations do
|
||||
desc 'export data for mysql import'
|
||||
task :export_for_mysql do
|
||||
require 'lib/mongo_to_mysql'
|
||||
migrator = MongoToMysql.new
|
||||
db_name = "diaspora-development"
|
||||
models = [
|
||||
:aspects,
|
||||
:comments,
|
||||
:contacts,
|
||||
:invitations,
|
||||
:notifications,
|
||||
:people,
|
||||
:posts,
|
||||
:requests,
|
||||
:users,
|
||||
]
|
||||
`mkdir -p #{Rails.root}/tmp/export-for-mysql`
|
||||
models.each do |model|
|
||||
filename = "#{Rails.root}/tmp/export-for-mysql/#{model}.json"
|
||||
`mongoexport -d #{db_name} -c #{model} | #{migrator.id_sed} | #{migrator.date_sed} > #{filename}`
|
||||
puts "#{model} exported to #{filename}"
|
||||
#`mongoexport -d #{db_name} -c #{model} -jsonArray | sed 's/\"[^"]*\"/"IAMID"/g' > #{filename}`
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue