Rake db:migrate在heroku上无声地失败

时间:2014-11-10 22:32:52

标签: ruby-on-rails ruby heroku rake

我有一个应用程序,我可以使用env = prod在本地运行,可以部署但我无法在heroku上运行任何rake命令。

  • 我在ENV = production中让我的服务器在本地运行。在我创建数据库之前,它以与heroku完全相同的方式失败,然后在我执行db:setup之后工作正常。问题肯定是我在heroku上创建数据库的命令失败了。

  • 如果我跑" heroku运行echo"你好"我得到输出"你好"。我在Heroku上运行命令的一般能力不是问题。

  • 但如果我跑#34; heroku运行rake [ANY_COMMAND]我没有输出和无声失败。

  • 如果我执行heroku运行bash然后rake db:migrate而不指定环境它运行良好

  • 如果我执行heroku运行bash然后rake db:migrate ENV =" production"我得到

    ActiveRecord::SchemaMigration Load (1.0ms)  SELECT "schema_migrations".* FROM "schema_migrations"
    

然后别的什么。回到活动的bash提示符。没有错误

  • 如果我做了heroku运行bash然后rake db:setup RAILS_ENV =" production"我明白了:

    FATAL:  permission denied for database "postgres"
    DETAIL:  User does not have CONNECT privilege.
    

    无法为{&#34;适配器&#34; =&gt;&#34; postgresql&#34;,&#34;用户名&#34; =&gt;&#34; dangfjubjcfyxp&#34创建数据库;,&#34;密码&#34; =&gt;随机字符串[已删除],&#34;端口&#34; =&gt; 5432,&#34;数据库&#34; =&gt; [删除]} < / p>

不确定是否只是因为你不应该在heroku上运行该命令,或者这实际上是一个问题。

  • 如果我进入heroku pg:psql并运行\ l(列表)或\ dg(列表用户)我会得到充满乱语的巨大表格。不确定是否预期。

  • 将我的heroku应用程序吹走,从头开始并得到相同的结果

    #ROOT/bin/rake
    #!/usr/bin/env ruby
    begin
      load File.expand_path("../spring", __FILE__)
    rescue LoadError
    end
    require_relative '../config/boot'
    require 'rake'
    Rake.application.run
    

这让我觉得可能有关于rake的bin目录配置之一被搞砸了。也许引用&#34; PATH&#34; ?

其他一些可能的相关文件:

#ROOT/Procfile
web: bundle exec rails server thin -p $PORT -e $RACK_ENV

#ROOT/config/production.rb
Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Set to :debug to see everything in the log.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Disable automatic flushing of the log to improve performance.
  # config.autoflush_log = false

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

如果发布任何其他文件对我有帮助,请告诉我

我有另一个类似的问题here,它显示了我的更多文件,但我认为我的理解已经充分改变,完全重新构思了问题,所以我会发布一篇新文章更好。

2 个答案:

答案 0 :(得分:0)

不确定所描述的行为是否真实存在且问题,但工作流程似乎存在缺陷。

您应该在本地开发应用程序,运行迁移等,然后提交更改并在接收推送后git push heroku master - heroku将执行所有工作:创建新blob,为您运行迁移,然后重新启动应用程序(运行Procfile中定义的所有Web进程和工作进程:https://devcenter.heroku.com/articles/procfile)。

如果它只是标准的普通轨道应用程序,你甚至不需要procfile - 只需将它推送到heroku。

答案 1 :(得分:0)

对我来说,我需要运行heroku run rake db:seed,然后一切正常。