Note: this is my first time configuring a rails application, deploying a rails app and setting up a database. I very well might be doing something obviously stupid.
I have a working rails application setup with postgres 9.3. I can run migrations, run my server locally and get a running application locally.
I pushed my code up to heroku and at one point it ran. Now when I run the heroku console it shows that my database is totally empty and I cannot figure out how to recreate it.
I am using v 0.17.1 of the pg gem.
Here are the steps I have taken.
1) Created my database.yml
development: adapter: postgresql encoding: unicode database: fr_development pool: 5 username: user password: password test: adapter: postgresql encoding: unicode database: fr_test pool: 5 username: user password: password production: url: <%= ENV['DATABASE_URL'] %>
1.5) setup my heroku account and installed papertrail
2) Made sure my schema.rb and all migrations are under source control.
3) ran "git push heroku master"
4) ran "heroku run db:drop db:setup --app app" or alternately sometime "heroku pg:reset DATABASE_URL"
5) ran "heroku run rake db:migrate --app app"
6) ran "heroku restart --app app"
Basically no matter what I run, all i get in papertrail is:
Nov 09 11:19:50 app heroku/api: Starting process with command `bundle exec rake db:drop db:create db:migrate RAILS_ENV=production` by email@example.com Nov 09 11:19:53 app heroku/run.3003: Awaiting client Nov 09 11:19:53 app heroku/run.3003: Starting process with command `bundle exec rake db:drop db:create db:migrate RAILS_ENV=production` Nov 09 11:19:53 app heroku/run.3003: State changed from starting to up Nov 09 11:19:54 app heroku/run.3003: Process exited with status 0 Nov 09 11:19:54 app heroku/run.3003: State changed from up to complete
And then if I hit my server Ill get an error that one of my relations doesnt exist.
If I "heroku run console" and try to run any of my tables it will say they dont exist.
One thing I no nothing about and am having a hard time finding resources to learn about is proper configurations for bin directory stuff. I have not touched
my bin/bundle is totally empty
#!bin/rails begin load File.expand_path("../spring", __FILE__) rescue LoadError end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands'
#bin/rake begin load File.expand_path("../spring", __FILE__) rescue LoadError end require_relative '../config/boot' require 'rake' Rake.application.run
#bin/spring unless defined?(Spring) require "rubygems" require "bundler" if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) ENV["GEM_HOME"] = "" Gem.paths = ENV gem "spring", match require "spring/binstub" end end
if I run heroku pg:info i get
HEROKU_POSTGRESQL_ONYX_URL (DATABASE_URL) Plan: Hobby-dev Status: Available Connections: 1/20 PG Version: 9.3.3 Created: 2014-11-06 04:08 UTC Data Size: 6.5 MB Tables: 0 Rows: 0/10000 (In compliance) Fork/Follow: Unsupported Rollback: Unsupported
One last thing that may be relevant I keep seeing this stack trace in paper trail although I'm not sure if it is just what happens when I reset the app:
[2014-11-10 03:39:58] FATAL SignalException: SIGTERM Nov 09 19:39:58 app app/web.1: /app/vendor/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:170:in `select' Nov 09 19:39:58 app app/web.1: /app/vendor/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:170:in `block in start' Nov 09 19:39:58 app app/web.1: /app/vendor/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:32:in `start' Nov 09 19:39:58 app app/web.1: /app/vendor/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:160:in `start' Nov 09 19:39:58 app app/web.1: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run' Nov 09 19:39:58 app app/web.1: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start' Nov 09 19:39:58 app app/web.1: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.1.5/lib/rails/commands/server.rb:69:in `start'
I have really tried to debug this one but I am out of ideas. Any help would be greatly appreciated.
other note: I setup postgres for the first time right before this. I was mucking around with it alot destorying and creating users and destroying and creating tables but I got everything back to a functional state locally. Don't know if that could somehow play into this.Answer1:
Just to make sure, if you haven't already, first run:
heroku run rake db:migrate
And if then if that doesn't work:
Followed by the heroku run rake db:migrate again.
By the way, I don't think Heroku gives you permission to to drop or create. Thus they've implemented pg:reset.
I found the devcenter doc that mentions permissions for dropping and creating and on using pg:reset here: <a href="https://devcenter.heroku.com/articles/rake" rel="nofollow">https://devcenter.heroku.com/articles/rake</a>