【问题标题】:RSpec "Migrations Are Pending" on HerokuHeroku 上的 RSpec“迁移待定”
【发布时间】:2015-04-23 05:03:49
【问题描述】:

在运行 Rails 4.2、Ruby 2.2.0 和 Rspec 3.2 时,我在运行 Rspec 时收到此错误:

rake aborted!
PG::ConnectionBad: FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
-e:1:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
/Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:393:in `check_pending!':  (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

    bin/rake db:migrate RAILS_ENV=test

    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:406:in `load_schema_if_pending!'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `block in maintain_test_schema!'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:640:in `suppress_messages'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:417:in `method_missing'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:412:in `maintain_test_schema!'
    from /Users/ahanmalhotra/Dropbox/Vocabulist/vocabulist/spec/rails_helper.rb:18:in `<top (required)>'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `require'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `block in requires='
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `each'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1181:in `requires='
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:110:in `block in process_options_into'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:109:in `each'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:109:in `process_options_into'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration_options.rb:22:in `configure'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:96:in `setup'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in `run'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:in `run'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.2.0/exe/rspec:4:in `<top (required)>'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/gemsets/vocabulist/bin/rspec:23:in `load'
    from /Users/ahanmalhotra/.rbenv/versions/2.2.0/gemsets/vocabulist/bin/rspec:23:in `<main>'

我的测试数据库在 Heroku 上,我认为 RSpec 正在尝试删除测试数据库并重新创建它。这在 Heroku 上是不允许的,所以这就是出现 permission denied 错误的原因。如果您配置一个全新的数据库并首次运行 RSpec,则不会出现此错误;第一次发生错误后。关于修复的任何想法?

谢谢!

【问题讨论】:

  • 这不是在生产中。这是在我的本地机器和我的 Bamboo 服务器上。它们都指向 Heroku 上的同一个测试数据库。
  • 正如您所说,Heroku 不允许您删除数据库,因此这不是托管您的开发数据库的好平台。

标签: ruby-on-rails ruby postgresql heroku rspec


【解决方案1】:

绝对没有理由将 Heroku db 用于测试目的,因为测试数据库每次都会在测试套装开始之前重新创建。你应该使用本地机器进行运行测试,或者如果测试套件太大而你的开发机器速度很慢,请使用 Travis、Semaphore、Circle CI、Snap CI、Codeship 等 CI 服务。

【讨论】:

  • 感谢您的回答!那么对于 Atlassian Bamboo,我应该只使用本地 Postgres 数据库吗?这个设置过去可以正常工作,但是当我升级 Rails 和 RSpec 时,它坏了。
  • 看,当您在本地机器上处理代码时,您在本地使用 2 个数据库:开发和测试。当您认为是时候将您的应用推送到生产环境时,您可以将应用推送到 Heroku,在 Heroku 上运行迁移并加载种子(如果需要)。因此,您在 Heroku 上的应用程序将使用放置在 Heroku 上的数据库。 Heroku 的堆栈与您的本地环境之间没有关联。我错过了什么吗?也许你的设置有问题?您可以分享更多信息,我会尽力提供帮助。
  • 我在 heroku 上有一个名为 blah_test 的 postgres 数据库。在我的开发机器和 Atlassian Bamboo CI 实例上,我正在使用数据库 blah_test 运行 rspec。然后我应该为 Atlassian Bamboo 使用哪个数据库?我应该为每台机器使用本地机器吗?
  • @AhanMalhotra 您的开发流程可能是这样的:编写代码,为此代码运行测试(在本地使用本地测试数据库),如果可以,将您的新代码推送到 CI(或带有 CI 集成的 Github已建立)所有测试将在哪里运行(CI 将使用它自己的测试数据库),然后如果测试也是绿色的,则将您的代码推送到 heroku(您的应用程序将使用它自己的,而不是共享的生产层数据库)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-13
  • 1970-01-01
  • 1970-01-01
  • 2015-10-25
  • 2019-11-15
  • 2018-11-18
  • 2018-03-07
相关资源
最近更新 更多