LINUX.ORG.RU

настроить db-конфиг для heroku?

 , ,


0

1

помогите пожалуйста решить проблему.

я сделал сайт. в режиме разработки использовал sqlite3. database.yml:

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  database: mysterious-badlands-7572_production
  pool: 5
  username: mysterious-badlands-7572
  password: blabla

gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '3.2.0.0'
gem 'bcrypt', '~> 3.1.7'
gem 'populate'
gem 'faker'
gem 'russian', '~> 0.6.0'
gem 'will_paginate'
gem 'paperclip'
gem 'fancybox2-rails', '~> 0.2.8'
gem 'rspec-rails'
gem 'factory_girl'
gem 'database_cleaner'

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

на локальном сервере сайт работает. я закачал его на heroku. в результате получаю следующее сообщение об ошибке:

500 internal server error

heroku использует postgresql и у меня подозрение, что я неправильно настроил конфиг. в этом проблема. помогите пожалуйста настроить конфиг

если интересно, то вот ссылка на сайт https://mysterious-badlands-7572.herokuapp.com/

mysterious-badlands-7572 это моё username. я его взял из личного кабинета heroku. в database.yml в секции production я вводил пароль, который я использую для входа в личный кабинет heroku.

Ответ на: комментарий от kelyar

вот часть лога:

kalinin@kalinin ~/rails/ZSUM $ heroku logs
2015-07-10T13:12:15.560745+00:00 app[web.1]:                ORDER BY a.attnum
2015-07-10T13:12:15.560746+00:00 app[web.1]: ):
2015-07-10T13:12:15.560747+00:00 app[web.1]:     1: <div class="auth_area col-xs-12 col-sm-10">
2015-07-10T13:12:15.560748+00:00 app[web.1]:     2:   <% if signed_in? %>
2015-07-10T13:12:15.560750+00:00 app[web.1]:     3:     <span class="entered_name"><%= t(:logged_on) %> <%= link_to current_user.name, user_path(current_user.id) %></span>
2015-07-10T13:12:15.560752+00:00 app[web.1]:     4:     (<%= link_to t(:sign_out), signout_path, method: "delete"  %>) 
2015-07-10T13:12:15.560754+00:00 app[web.1]:     5:     <%= link_to t(:to_admininterface), admin_users_path, class: 'to_admininterface' if current_user.admin? %>
2015-07-10T13:12:15.560755+00:00 app[web.1]:   app/helpers/sessions_helper.rb:15:in `current_user'
2015-07-10T13:12:15.560759+00:00 app[web.1]:   app/views/layouts/_auth_area.html.erb:2:in `_app_views_layouts__auth_area_html_erb__1107687738616090184_69903718216080'
2015-07-10T13:12:15.560762+00:00 app[web.1]: 
2015-07-10T13:12:15.560763+00:00 app[web.1]: 
2015-07-10T13:12:15.560757+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `signed_in?'
2015-07-10T13:12:15.560761+00:00 app[web.1]:   app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___1862214377627635116_69903711517060'
2015-07-10T13:12:15.813733+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=mysterious-badlands-7572.herokuapp.com request_id=67447ad3-aa57-4f49-aa07-0fb113ebb5e7 fwd="31.204.102.26" dyno=web.1 connect=2ms service=5ms status=200 bytes=228
2015-07-10T13:12:17.966043+00:00 heroku[router]: at=info method=GET path="/" host=mysterious-badlands-7572.herokuapp.com request_id=81ef5a6e-3a12-418b-b942-0a88bd63da5e fwd="31.204.102.26" dyno=web.1 connect=4ms service=14ms status=500 bytes=339
2015-07-10T13:12:17.953581+00:00 app[web.1]: Started GET "/" for 31.204.102.26 at 2015-07-10 13:12:17 +0000
2015-07-10T13:12:17.957410+00:00 app[web.1]:   Rendered pages/home.html.erb within layouts/application (0.6ms)
2015-07-10T13:12:17.961281+00:00 app[web.1]: Completed 500 Internal Server Error in 5ms (ActiveRecord: 2.0ms)
2015-07-10T13:12:17.955804+00:00 app[web.1]: Processing by PagesController#home as HTML
2015-07-10T13:12:17.960394+00:00 app[web.1]: PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-07-10T13:12:17.960398+00:00 app[web.1]: LINE 5:                WHERE a.attrelid = '"users"'::regclass
2015-07-10T13:12:17.960400+00:00 app[web.1]:                                           ^
2015-07-10T13:12:17.960401+00:00 app[web.1]: :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
2015-07-10T13:12:17.960403+00:00 app[web.1]:                      pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
2015-07-10T13:12:17.960404+00:00 app[web.1]:                 FROM pg_attribute a LEFT JOIN pg_attrdef d
2015-07-10T13:12:17.960405+00:00 app[web.1]:                   ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2015-07-10T13:12:17.960406+00:00 app[web.1]:                WHERE a.attrelid = '"users"'::regclass
2015-07-10T13:12:17.960407+00:00 app[web.1]:                  AND a.attnum > 0 AND NOT a.attisdropped
2015-07-10T13:12:17.960408+00:00 app[web.1]:                ORDER BY a.attnum
2015-07-10T13:12:17.960410+00:00 app[web.1]: 
2015-07-10T13:12:17.961087+00:00 app[web.1]:   Rendered layouts/_auth_area.html.erb (2.9ms)
2015-07-10T13:12:17.962975+00:00 app[web.1]: 
2015-07-10T13:12:17.962979+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-07-10T13:12:17.962981+00:00 app[web.1]: LINE 5:                WHERE a.attrelid = '"users"'::regclass
2015-07-10T13:12:17.962983+00:00 app[web.1]:                                           ^
2015-07-10T13:12:17.962988+00:00 app[web.1]:                 FROM pg_attribute a LEFT JOIN pg_attrdef d
2015-07-10T13:12:17.962985+00:00 app[web.1]: :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
2015-07-10T13:12:17.962987+00:00 app[web.1]:                      pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
2015-07-10T13:12:17.962990+00:00 app[web.1]:                   ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2015-07-10T13:12:17.962992+00:00 app[web.1]:                WHERE a.attrelid = '"users"'::regclass
2015-07-10T13:12:17.962995+00:00 app[web.1]:                ORDER BY a.attnum
2015-07-10T13:12:17.962993+00:00 app[web.1]:                  AND a.attnum > 0 AND NOT a.attisdropped
2015-07-10T13:12:17.962997+00:00 app[web.1]: ):
2015-07-10T13:12:17.962998+00:00 app[web.1]:     1: <div class="auth_area col-xs-12 col-sm-10">
2015-07-10T13:12:17.963000+00:00 app[web.1]:     2:   <% if signed_in? %>
2015-07-10T13:12:17.963002+00:00 app[web.1]:     3:     <span class="entered_name"><%= t(:logged_on) %> <%= link_to current_user.name, user_path(current_user.id) %></span>
2015-07-10T13:12:17.963004+00:00 app[web.1]:     4:     (<%= link_to t(:sign_out), signout_path, method: "delete"  %>) 
2015-07-10T13:12:17.963006+00:00 app[web.1]:     5:     <%= link_to t(:to_admininterface), admin_users_path, class: 'to_admininterface' if current_user.admin? %>
2015-07-10T13:12:17.963008+00:00 app[web.1]:   app/helpers/sessions_helper.rb:15:in `current_user'
2015-07-10T13:12:17.963010+00:00 app[web.1]:   app/helpers/sessions_helper.rb:23:in `signed_in?'
2015-07-10T13:12:17.963013+00:00 app[web.1]:   app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___1862214377627635116_69903711517060'
2015-07-10T13:12:17.963011+00:00 app[web.1]:   app/views/layouts/_auth_area.html.erb:2:in `_app_views_layouts__auth_area_html_erb__1107687738616090184_69903718216080'
2015-07-10T13:12:17.963015+00:00 app[web.1]: 
2015-07-10T13:12:17.963016+00:00 app[web.1]: 
2015-07-10T13:12:25.999811+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by kalinin.sergey.81@gmail.com
2015-07-10T13:12:30.012127+00:00 heroku[run.3406]: Awaiting client
2015-07-10T13:12:30.096429+00:00 heroku[run.3406]: Starting process with command `bundle exec rake db:migrate`
2015-07-10T13:12:30.251044+00:00 heroku[run.3406]: State changed from starting to up
2015-07-10T13:12:36.121820+00:00 heroku[run.3406]: State changed from up to complete
2015-07-10T13:12:36.106249+00:00 heroku[run.3406]: Process exited with status 1
2015-07-10T13:23:10.706134+00:00 heroku[router]: at=info method=GET path="/" host=mysterious-badlands-7572.herokuapp.com request_id=f99f1f1f-7366-4642-970d-c602472c4e5e fwd="91.193.69.66" dyno=web.1 connect=2ms service=10ms status=500 bytes=339

prozaik ()
Ответ на: комментарий от neversleep

пробовал:

kalinin@kalinin ~/rails/ZSUM $ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.2471
  ActiveRecord::SchemaMigration Load (1.0ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to Passfield (20150609115251)
   (3.6ms)  BEGIN
== 20150609115251 Passfield: migrating ========================================
-- rename_column(:users, :password_hash, :password_digest)
   (1.5ms)  ALTER TABLE "users" RENAME COLUMN "password_hash" TO "password_digest"
PG::UndefinedTable: ERROR:  relation "users" does not exist
: ALTER TABLE "users" RENAME COLUMN "password_hash" TO "password_digest"
   (0.8ms)  ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR:  relation "users" does not exist
: ALTER TABLE "users" RENAME COLUMN "password_hash" TO "password_digest"/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
...........
..........
......
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

дело в том, что я с файлами миграций немного накосячил. в течение работы над проектом некоторые стёр. это не мешало так как schema.rb содержал актуальную версию. но на heroku, видимо, все миграции последовательно прогоняются....

prozaik ()
Ответ на: комментарий от prozaik

Давно с хероку не работал, но разве rake db:setup там нельзя сделать?

p.s. в будущем советую одинаковую базу во всех окружениях использовать

Nucleus- ()

А вот конфиг рабочий, в production вроде не надо никаких данных, он сам все создает.

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  <<: *default
  encoding: unicode
  host: localhost
  database: flashcard
  username: ***
  password: ***

production:
  <<: *default
  database: db/production.postgresql

test:
  <<: *default
  encoding: unicode
  host: localhost
  database: test_flashcard
  username: ***
  password: ***

Nucleus- ()
Ответ на: комментарий от prozaik

спасибо, чуваки. проблема была действительно в загрузке структуры БД. сейчас я загрузил струтуру не из последовательности миграций, а из файла schema.rb и сайт заработал

prozaik ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.