adacosta / mongoid_rails_migrations Goto Github PK
View Code? Open in Web Editor NEWData migrations for Mongoid.
Data migrations for Mongoid.
rails version 4.1.6
mongoid 4.0.0
ruby-2.1.1
rails generate mongoid:migration convert_location_to_venue
/Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/mongoid_rails_migrations-1.0.1/lib/rails/generators/mongoid/mongoid_generator.rb:17:in `next_migration_number': undefined method `timestamped_migrations' for Mongoid::Config:Module (NoMethodError)
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/generators/migration.rb:41:in `set_migration_assigns!'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/generators/migration.rb:57:in `migration_template'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/mongoid_rails_migrations-1.0.1/lib/rails/generators/mongoid/migration/migration_generator.rb:8:in `create_migration_file'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/generators.rb:157:in `invoke'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/commands/generate.rb:11:in `<top (required)>'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:135:in `generate_or_destroy'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/regis.leray/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
zOMG I AM SUPER FAN BOI OF NOSQL AND I HEARD THAT NOSQL GETS RID OF THE NEED FOR MIGRATIONS SO WHY DO WE NEED THIS?>
Hi, Not sure how to test this project,
bundle exec rake test:mongoid:migrations
wont work.
Having a travis setup would be helpful so people know how to run tests.
rake db:migrate VERSION=202201010101
My current workaround is a monkeypatch hack of Mongoid::Migrator.migrate
to gracefully exit from mongo migrations. It's an ORM specific (ActiveRecord) solution. Ultimately I think the correct course of action is completely divorcing mongoid_rails_migrations
from db:migrate
and other default ActiveRecord rake tasks. However this is breaking behavior.
I'm happy to code up solutions to this if you have any other suggestions on reasonable/generic ways to solve this.
My monkey patch:
module Mongoid
class Migrator
class << self
# override from https://github.com/adacosta/mongoid_rails_migrations/blob/2b8b1c98bac36d0332f7408c0ca2d8a9da308e37/lib/mongoid_rails_migrations/active_record_ext/migrations.rb#L205
# This allows us to handle non-Mongo migration versions gracefully
alias :old_migrate :migrate
def migrate(migrations_path, target_version = nil)
target_mongo_version_exists = Mongoid::Migrator.get_all_versions.index(target_version.to_i)
target_rails_version_exists = ActiveRecord::Base.connection.migration_context.migrations.index { |migration| migration.version == target_version.to_i }
if target_mongo_version_exists || (target_rails_version_exists.nil? && target_mongo_version_exists.nil?)
old_migrate(migrations_path, target_version)
elsif target_rails_version_exists
# There is a valid migration here for Rails so just exit
return
else
# we shouldn't actually ever hit this case as the rails migration rake task should error out before we get here
# this is included for completeness and safety
raise Mongoid::UnknownMigrationVersionError.new(target_version)
end
end
end
end
end
Note that this patch does not allow you to run mongoid migrations via db:migrate VERSION=
. It simply allows you to run rails migrations without erroring. I wrote up separate rake tasks for mongoid migrate tasks targeting a version. I really didn't feel like patching ActiveRecord just to get this to work.
When using this gem with Rails 5.0, the following deprecation warning appears
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super.
It appears to be used here
alias_method_chain
has also been removed in Rails 5.1. rails/rails#27035
Hey, great work! I've been using this gem recently an I've found it helpful, thanks!
I've come to get this issue when using the last released version of the gem, but it seems it has been solved on the master branch. Are you planing on realeasing a new version any time soon? That would be great.
Thanks again!
When I run db:reseed, I expect that my data is generated to the current, most up-to-date schema and all of my migrations have been run.
Is it implemented already?
I have a class MigrateHistoriesToMongodb < Mongoid::Migration with the usual up and down functions in db/migrate.
Is this a 3.1 issue of some kind that needs to be resolved, or is it something else?
undefined method `migrate' for #<MigrateHistoriesToMongodb:0x000001045c2060>
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:507:in `migrate'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:687:in `block (2 levels) in migrate'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:742:in `call'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:742:in `block in ddl_transaction'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/transactions.rb:208:in `transaction'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:742:in `ddl_transaction'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:686:in `block in migrate'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:671:in `each'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:671:in `migrate'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:549:in `up'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/migration.rb:530:in `migrate'
/Users/patrick/develop/trendmover.com/sqlite3/ruby/1.9.1/gems/activerecord-3.1.0.rc6/lib/active_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
/Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
Steps to reproduce:
worker: bundle exec rake db:migrate
bundle exec foreman start
Stacktrace:
13:20:48 worker.1 | started with pid 85087
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/version.rb:3: warning: already initialized constant JSON::VERSION
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/version.rb:4: warning: previous definition of VERSION was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/version.rb:4: warning: already initialized constant JSON::VERSION_ARRAY
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/version.rb:5: warning: previous definition of VERSION_ARRAY was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/version.rb:5: warning: already initialized constant JSON::VERSION_MAJOR
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/version.rb:6: warning: previous definition of VERSION_MAJOR was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/version.rb:6: warning: already initialized constant JSON::VERSION_MINOR
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/version.rb:7: warning: previous definition of VERSION_MINOR was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/version.rb:7: warning: already initialized constant JSON::VERSION_BUILD
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/version.rb:8: warning: previous definition of VERSION_BUILD was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/common.rb:99: warning: already initialized constant JSON::NaN
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/common.rb:100: warning: previous definition of NaN was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/common.rb:101: warning: already initialized constant JSON::Infinity
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/common.rb:102: warning: previous definition of Infinity was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/common.rb:103: warning: already initialized constant JSON::MinusInfinity
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/common.rb:104: warning: previous definition of MinusInfinity was here
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/lib/ruby/2.2.0/json/common.rb:128: warning: already initialized constant JSON::UnparserError
13:20:51 worker.1 | /Users/m/.bundler/gems/json-2.0.3/lib/json/common.rb:129: warning: previous definition of UnparserError was here
13:20:51 worker.1 | rake aborted!
13:20:51 worker.1 | LoadError: cannot load such file -- active_model/naming
13:20:51 worker.1 | /Users/m/.bundler/gems/activemodel-5.0.2/lib/active_model/validations.rb:42:in `block in <module:Validations>'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:120:in `class_eval'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:120:in `append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `include'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `block in append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `each'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `include'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `block in append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `each'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `include'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `block in append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `each'
13:20:51 worker.1 | /Users/m/.bundler/gems/activesupport-5.0.2/lib/active_support/concern.rb:117:in `append_features'
13:20:51 worker.1 | /Users/m/.bundler/gems/mongoid_rails_migrations-1.1.0/lib/mongoid_rails_migrations/models/data_migration.rb:2:in `include'
13:20:51 worker.1 | /Users/m/.bundler/gems/mongoid_rails_migrations-1.1.0/lib/mongoid_rails_migrations/models/data_migration.rb:2:in `<class:DataMigration>'
13:20:51 worker.1 | /Users/m/.bundler/gems/mongoid_rails_migrations-1.1.0/lib/mongoid_rails_migrations/models/data_migration.rb:1:in `<top (required)>'
13:20:51 worker.1 | /Users/m/.bundler/gems/mongoid_rails_migrations-1.1.0/lib/mongoid_rails_migrations.rb:10:in `require'
13:20:51 worker.1 | /Users/m/.bundler/gems/mongoid_rails_migrations-1.1.0/lib/mongoid_rails_migrations.rb:10:in `<top (required)>'
13:20:51 worker.1 | /Users/m/projects/rails5/testapp/config/application.rb:7:in `<top (required)>'
13:20:51 worker.1 | /Users/m/projects/rails5/testapp/Rakefile:4:in `require_relative'
13:20:51 worker.1 | /Users/m/projects/rails5/testapp/Rakefile:4:in `<top (required)>'
13:20:51 worker.1 | /Users/m/.bundler/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/bin/bundle:23:in `load'
13:20:51 worker.1 | /Users/m/.rbenv/versions/2.2.5/bin/bundle:23:in `<main>'
13:20:51 worker.1 | (See full trace by running task with --trace)
13:20:52 worker.1 | exited with code 1
13:20:52 system | sending SIGTERM to all processes
Basically running rake db:migrate
twice in a row reverts the previous migration. I would have expected it to do nothing the second time. Is this a feature or a bug?
Hi there,
Thanks for the awesome gem btw. It's been very helpful.
I'm wondering if there is a convenient way to turn off the identity_map during migrations? If identity_map is on, mongoid will not know when to clear it (since migrations aren't web requests) and the migration process will continue to use more and more memory as you iterate over large datasets.
It's the same problem described here: http://dev.mensfeld.pl/2011/09/ruby-mongoid-and-memory-leaks-identity-map-problem/
So far I've just been setting Mongoid.identity_map_enabled = false
at the top of def self.up
, but it's easy to forget. Thanks!
Would be great to have an easy way to see what migrations have been run
Hey @adacosta, travis.org is going away and I can't migrate the project to travis.com as I'm not the owner of the repo. Could you please do it? (or transfer the repo to me if you prefer) Thanks!
When I am running all the test using RSpec guard and mongoid_rails_migrations, I am getting
bundler: failed to load command: rspec (/home/vivek/.rbenv/versions/2.3.1/bin/rspec)
LoadError: cannot load such file -- active_model/naming
But when I remove the gem from my Gemfile, RSpec guard runs fine.
http://rubygems.org/gems/mongoid_rails_migrations
You haven't pushed up a new release of the gem since May 2010, are you going to push up a new version or should we just point bundler to the git repo and a specific tag?
Spent quite some time to realize how to override default migrations_path
. Adding this to README.md
can save some time for others.
Thanks for the great gem. I'm having issues to upgrade my app to rails 3.1.0.rc1 because there is a dependency to rails 3.0.x in your gemspec. Could you change this to be ">= 3.0.0" ? Or does the gem not run with rails 3.1.0?
Thanks
Andi
Commit ba7e2eae044e6c8213d8 to Mongoid changes Mongoid::Config from a Class to a Module. This was first released in version 2.0.0.rc.1 of Mongoid and breaks compatibility with the current version of mongoid_rails_migrations. I haven't looked into updating mongoid_rails_migrations but I wonder whether a quicker fix would be to update the gem dependency in the gemspec to explicitly state that it works with '>= 2.0.0.beta.17' and '<= 2.0.0.beta.20'.
A project which uses Bundler and the mongoid_rails_migrations gem will see its gems loaded twice.
It's because of these two lines lib/mongoid_rails_migrations.rb.
require 'bundler/setup'
Bundler.require(:default)
You can see that by adding a puts file
next to Kernel.require file
, in bundler-1.0.x/lib/bundler/runtime.rb.
I guess these lines are useful for development and test of the gem itself, so they should be moved to your Rakefile.
The gemspec, starting with 0.0.7, declares a dependency on rails ~> 3.0.0
. That means the latest mongoid_rails_migrations gem that can be used with the Rails 3.1 beta is 0.0.6 which isn't compatible with Mongoid 2.0 RC1 or newer. The gemspec should declare its rails dependency as ~> 3.0
just like Mongoid itself.
Is it possible to use Mongoid and ActiveRecord migrations in the same app? Right now ActiveRecord is taking precedence when running rake db:migrate
It would be great if support rails 4.1.x
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
mongoid_rails_migrations (~> 1.1.0) ruby depends on
activesupport (>= 4.2.0) ruby
jbuilder (~> 2.0) ruby depends on
activesupport (4.1.8)
Hey, since installing this gem I get these weird "error" messages whenever running rails generate, rspec or rails server in my development environment.
port is not a valid option for Mongo::Connection
host is not a valid option for Mongo::Connection
It's probably related to my mongoid.yml
<%if ENV['RAILS_ENV'] != 'production'
credentials = YAML.load_file('config/db.credentials.yml')[ENV['RAILS_ENV']]
username = credentials['user']
password = credentials['password']
port = credentials['port']
host = credentials['url']
database = credentials['database']
end
%>
development:
username: <%= username %>
password: <%= password %>
port: <%= port %>
host: <%= host %>
database: <%= database %>
test:
username: <%= username %>
password: <%= password %>
port: <%= port %>
host: <%= host %>
database: <%= database %>
# set these environment variables on your prod server
production:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
When I do
rails db:migrate
I get this error:
ArgumentError: wrong number of arguments (given 2, expected 0)
When I remove active record and remove all migrations related to it, then it works with mongoid.
When I migrate Active record migrations, I have to remove all migrations related to Mongoid.
I am using MySQL and Mongo on my application simultaneously.
Hello,
First of all, found this after quite a bit of frustration, so thank you so much. I seem to be having some trouble though, and it's sure I'm misunderstanding. In the end, the answer to this question doesn't really matter as it's a simple manual fix regardless.
I run: rails generate mongoid:migration add_birthday_to_users birthday:date
It creates the migration no problem, but it's empty.
class AddBirthdayToUsers < Mongoid::Migration
def self.up
end
def self.down
end
end
Is this how it's designed? Does this simply create the migration skeleton? I've already done the manual work necessary, I'm just asking for future reference to make sure I'm not missing something. Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.