Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails 5.2.4.3 raises PendingMigrationsError when using NullDB #93

Closed
coldnebo opened this issue Jun 4, 2020 · 3 comments
Closed

rails 5.2.4.3 raises PendingMigrationsError when using NullDB #93

coldnebo opened this issue Jun 4, 2020 · 3 comments

Comments

@coldnebo
Copy link

coldnebo commented Jun 4, 2020

ERROR

Trying to run 'rake spec' while using nulldb I get this error:

$ rake spec
Migrations are pending. To resolve this issue, run:

        bin/rails db:migrate RAILS_ENV=test

CONFIGURATION

  • The Rails app has migrations in db/migrations.
  • We are using the default rails_helper.rb from rspec-rails, which runs under RAILS_ENV='test'

Environment:

ruby 2.6.6 (linux)
rails (5.2.4.3)
rspec-rails (4.0.1)
activerecord (5.2.4.3)
activerecord-nulldb-adapter (0.4.0)

database.yml defines

test: 
  adapter: nulldb

WORKAROUND

Adding this to the end of config/environments/test.rb fixes the problem and allows the specs to run:

module ActiveRecord
  class MigrationContext 
    def needs_migration?
      false
    end
  end
end
@ekohl
Copy link

ekohl commented Sep 5, 2020

I also ran into this. A more flexible patch is:

module NullDBMigrationContextPatch
  def needs_migration?
    return false if schema_migration.connection.adapter_name == 'NullDB'
    super
  end
end

class ActiveRecord::MigrationContext
  prepend NullDBMigrationContextPatch
end

@coldnebo
Copy link
Author

coldnebo commented Sep 9, 2020

That is very slick! Thanks!

@cabello cabello pinned this issue Oct 13, 2020
@cabello cabello closed this as completed Oct 28, 2021
@cabello
Copy link

cabello commented Oct 28, 2021

Leaving this as pinned but closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants