Reputation: 9789
I want to run a data transformation / migration for MongoDB. I found the mongo_mapper_ext gem on stackoverflow, but I guess I'm so new to migrations in general that I'm not sure how to use it.
My Rails app is deployed on heroku. So I think once I write the migration and push it to heroku, I should be able to run heroku rake:db migrate. Is that correct, or should that migration be run in an application initializer?
When I write the migration itself, where does that file go in my app directory?
https://github.com/alexeypetrushin/mongo_mapper_ext
Any advice on the best way to do this would be so helpful. Thank you!
Upvotes: 0
Views: 74
Reputation: 4440
if you look at mongo_mapper_ext's rake task, it looks like you would put the migrations file(s) in the db directory under your rails application.
namespace :db do
desc "Migrate Database"
task migrate: :environment do
::Migration = MongoMapper::Migration
Dir["#{rad.config.runtime_dir!}/db/**/*.rb"].each{|f| require f.sub(/\.rb$/, '')}
database_alias = ENV['d'] || ENV['database']
database_alias = 'default' if database_alias.blank?
version = ENV['v'] || ENV['version']
if version.blank?
size = MongoMapper::Migration.definitions[database_alias].size
highest_defined_version = size == 0 ? 0 : size - 1
version = highest_defined_version
else
version = version.to_i
end
MongoMapper::Migration.update database_alias, version
end
end
Upvotes: 1