如何从ruby中检查heroku数据库版本

时间:2018-04-17 04:36:29

标签: ruby-on-rails ruby heroku

我想从在我的本地MacOS开发机器上运行的shell方法检查我的生产数据库的版本。从命令行,我可以成功运行

heroku run rake db:version --remote production

但如果我打开rails console会话并输入

hv = `heroku run rake db:version --remote production`

我看到以下错误消息:

/Users/Chris/.rvm/gems/ruby-2.5.1@golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/definition.rb:489:in `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.5.1 (Bundler::RubyVersionMismatch)
    from /Users/Chris/.rvm/gems/ruby-2.5.1@golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/definition.rb:464:in `validate_runtime!'
    from /Users/Chris/.rvm/gems/ruby-2.5.1@golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler.rb:101:in `setup'
    from /Users/Chris/.rvm/gems/ruby-2.5.1@golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/setup.rb:20:in `<top (required)>'
    from /usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require

我使用的是ruby 2.5.1。 heroku --version命令生成heroku-cli/6.16.13-dbb9c23 (darwin-x64) node-v9.11.1。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

事实证明这与此github https://github.com/bundler/bundler/issues/2489有关。看起来捆绑包被heroku cli文件中的shebang混淆了。解决方案是为bundler

使用干净的环境
Bundler.with_clean_env {`heroku run rake db:version --remote production`}