Skip to content
Extraits de code Groupes Projets
Valider 4e44b197 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Begin writing migration from mongo to mysql

parent 0328c167
Branches
Étiquettes
Aucune requête de fusion associée trouvée
# 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
# 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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter