我正在尝试使用postgres数据库将.rb文件部署到heroku。但是,在将文件推送到Heroku并运行它之后,我收到数据库的错误。我的基本问题是我不知道如何在.rb文件中启动postgres数据库,并将代码正确部署到Heroku。有人能帮我吗?
.rb文件包含以下行来启动数据库:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: ruby-getting-started_development
test:
<<: *default
database: ruby-getting-started_test
production:
<<: *default
database: ruby-getting-started_production
username: ruby-getting-started
password: <%= ENV['RUBY-GETTING-STARTED_DATABASE_PASSWORD'] %>
database.yml文件是:
source 'https://rubygems.org'
ruby '2.3.3'
gem 'sinatra'
# sinatra needs old tilt version: http://stackoverflow.com/questions/20648394/moduletemplates-uninitialized-constant-tiltcompilesite-nameerror-using
#https://groups.google.com/forum/#!topic/sinatrarb/mAtn7AZBVmY
gem 'tilt', '~> 1.4.1', group: :production
gem 'rest-client'
gem 'sequel'
gem 'sqlite3', group: :development
gem 'pg', '~> 0.18', group: :development
gem 'cowsay'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18', group: :production
gem 'rails_12factor', group: :production
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'puma'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
这是gemfile:
2016-12-29T23:17:02.130612+00:00 app[web.1]: [4] * Environment: production
2016-12-29T23:17:02.130612+00:00 app[web.1]: [4] * Process workers: 2
2016-12-29T23:17:02.130613+00:00 app[web.1]: [4] * Preloading application
2016-12-29T23:17:03.585155+00:00 app[web.1]: [4] ! Unable to load application: PG::ConnectionBad: could not connect to server: No such file or directory
2016-12-29T23:17:03.585170+00:00 app[web.1]: Is the server running locally and accepting
2016-12-29T23:17:03.585172+00:00 app[web.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2016-12-29T23:17:03.585225+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.3.0/bin/puma)
2016-12-29T23:17:03.585247+00:00 app[web.1]: PG::ConnectionBad: could not connect to server: No such file or directory
2016-12-29T23:17:03.585248+00:00 app[web.1]: Is the server running locally and accepting
2016-12-29T23:17:03.585249+00:00 app[web.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2016-12-29T23:17:03.585250+00:00 app[web.1]:
2016-12-29T23:17:03.585250+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `initialize'
2016-12-29T23:17:03.585251+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `new'
2016-12-29T23:17:03.585252+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `connect'
2016-12-29T23:17:03.585253+00:00 app[web.1]: /app/firebasepushserver.rb:31:in `<top (required)>'
2016-12-29T23:17:03.585254+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
2016-12-29T23:17:03.585256+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
2016-12-29T23:17:03.585256+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
2016-12-29T23:17:03.585257+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
2016-12-29T23:17:03.585258+00:00 app[web.1]: config.ru:5:in `block in <main>'
2016-12-29T23:17:03.585258+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
2016-12-29T23:17:03.585259+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
2016-12-29T23:17:03.585260+00:00 app[web.1]: config.ru:in `new'
2016-12-29T23:17:03.585261+00:00 app[web.1]: config.ru:in `<main>'
2016-12-29T23:17:03.585261+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
2016-12-29T23:17:03.585262+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
2016-12-29T23:17:03.585263+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
2016-12-29T23:17:03.585263+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/configuration.rb:315:in `load_rackup'
2016-12-29T23:17:03.585264+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/configuration.rb:243:in `app'
2016-12-29T23:17:03.585265+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/runner.rb:127:in `load_and_bind'
2016-12-29T23:17:03.585266+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:370:in `run'
2016-12-29T23:17:03.585266+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/launcher.rb:172:in `run'
2016-12-29T23:17:03.585267+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/cli.rb:74:in `run'
2016-12-29T23:17:03.585267+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/bin/puma:10:in `<top (required)>'
2016-12-29T23:17:03.585268+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:22:in `load'
2016-12-29T23:17:03.585269+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:22:in `<top (required)>'
2016-12-29T23:17:03.656423+00:00 heroku[web.1]: Process exited with status 1
2016-12-29T23:17:03.673289+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-29T23:41:22.415335+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user mjpablo23@gmail.com
2016-12-29T23:41:25.630947+00:00 heroku[run.7170]: Awaiting client
2016-12-29T23:41:25.666952+00:00 heroku[run.7170]: Starting process with command `bundle exec rake db:migrate`
2016-12-29T23:41:25.724663+00:00 heroku[run.7170]: State changed from starting to up
2016-12-29T23:41:32.206652+00:00 heroku[run.7170]: State changed from up to complete
2016-12-29T23:41:32.192296+00:00 heroku[run.7170]: Process exited with status 0
2016-12-29T23:41:51.140936+00:00 heroku[web.1]: State changed from crashed to starting
2016-12-29T23:41:55.556173+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2016-12-29T23:41:59.809729+00:00 app[web.1]: [4] Puma starting in cluster mode...
2016-12-29T23:41:59.809919+00:00 app[web.1]: [4] * Version 3.6.0 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
2016-12-29T23:41:59.809994+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2016-12-29T23:41:59.810069+00:00 app[web.1]: [4] * Environment: production
2016-12-29T23:41:59.810184+00:00 app[web.1]: [4] * Process workers: 2
2016-12-29T23:41:59.810294+00:00 app[web.1]: [4] * Preloading application
2016-12-29T23:42:04.051013+00:00 app[web.1]: [4] ! Unable to load application: PG::ConnectionBad: could not connect to server: No such file or directory
2016-12-29T23:42:04.051023+00:00 app[web.1]: Is the server running locally and accepting
2016-12-29T23:42:04.051024+00:00 app[web.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2016-12-29T23:42:04.051145+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.3.0/bin/puma)
2016-12-29T23:42:04.051215+00:00 app[web.1]: Is the server running locally and accepting
2016-12-29T23:42:04.051214+00:00 app[web.1]: PG::ConnectionBad: could not connect to server: No such file or directory
2016-12-29T23:42:04.051217+00:00 app[web.1]:
2016-12-29T23:42:04.051217+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `initialize'
2016-12-29T23:42:04.051218+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `new'
2016-12-29T23:42:04.051216+00:00 app[web.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2016-12-29T23:42:04.051219+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb:45:in `connect'
2016-12-29T23:42:04.051220+00:00 app[web.1]: /app/firebasepushserver.rb:31:in `<top (required)>'
2016-12-29T23:42:04.051223+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
2016-12-29T23:42:04.051221+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
2016-12-29T23:42:04.051224+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
2016-12-29T23:42:04.051224+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
2016-12-29T23:42:04.051225+00:00 app[web.1]: config.ru:5:in `block in <main>'
2016-12-29T23:42:04.051227+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
2016-12-29T23:42:04.051227+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
2016-12-29T23:42:04.051228+00:00 app[web.1]: config.ru:in `new'
2016-12-29T23:42:04.051229+00:00 app[web.1]: config.ru:in `<main>'
2016-12-29T23:42:04.051230+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
2016-12-29T23:42:04.051230+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
2016-12-29T23:42:04.051231+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
2016-12-29T23:42:04.051231+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/configuration.rb:315:in `load_rackup'
2016-12-29T23:42:04.051232+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/configuration.rb:243:in `app'
2016-12-29T23:42:04.051233+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/runner.rb:127:in `load_and_bind'
2016-12-29T23:42:04.051233+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/cluster.rb:370:in `run'
2016-12-29T23:42:04.051234+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/launcher.rb:172:in `run'
2016-12-29T23:42:04.051235+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/lib/puma/cli.rb:74:in `run'
2016-12-29T23:42:04.051235+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.6.0/bin/puma:10:in `<top (required)>'
2016-12-29T23:42:04.051236+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:22:in `load'
2016-12-29T23:42:04.051237+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:22:in `<top (required)>'
2016-12-29T23:42:04.201815+00:00 heroku[web.1]: Process exited with status 1
2016-12-29T23:42:04.201565+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-29T23:50:51.225592+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/register" host=favorsrubytest2.herokuapp.com request_id=a4839906-3bcf-41f3-959b-f24823d50a8a fwd="96.90.253.166" dyno= connect= service= status=503 bytes=
2016-12-29T23:51:28.906822+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/register" host=favorsrubytest2.herokuapp.com request_id=1fe24de4-94ed-4c27-8f6d-a650da5aee53 fwd="96.90.253.166" dyno= connect= service= status=503 bytes=
2016-12-29T23:57:59.851571+00:00 app[api]: Starting process with command `bundle exec rake db:schema:load` by user mjpablo23@gmail.com
2016-12-29T23:58:02.749520+00:00 heroku[run.7794]: Awaiting client
2016-12-29T23:58:02.793000+00:00 heroku[run.7794]: Starting process with command `bundle exec rake db:schema:load`
2016-12-29T23:58:03.049242+00:00 heroku[run.7794]: State changed from starting to up
2016-12-29T23:58:08.694759+00:00 heroku[run.7794]: State changed from up to complete
2016-12-29T23:58:08.679880+00:00 heroku[run.7794]: Process exited with status 0
2016-12-29T23:58:23.071987+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user mjpablo23@gmail.com
2016-12-29T23:58:27.092648+00:00 heroku[run.2844]: Awaiting client
2016-12-29T23:58:27.158662+00:00 heroku[run.2844]: Starting process with command `bundle exec rake db:migrate`
2016-12-29T23:58:27.228211+00:00 heroku[run.2844]: State changed from starting to up
2016-12-29T23:58:34.824401+00:00 heroku[run.2844]: Process exited with status 0
2016-12-29T23:58:34.841240+00:00 heroku[run.2844]: State changed from up to complete
这是错误:
files_found = 0
for root, dirs, files in os.walk(path):
for name in files:
if keyword in name.lower():
files_found += 1
time.sleep(0)
update_progress_bar()
print "Found {}".format(files_found)
答案 0 :(得分:0)
需要使用:
DB = Sequel.connect(ENV['DATABASE_URL'])