1

I have a Rails 4.2 app on Digital Ocean. After deploying a comments model (with a migrate file), it works fine in development, but not in production. I have been using Capistrano (per this tutorial - https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma) Deploys have been going fine until now.

This was my migrate file (missing from my deploy).

class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.references :user, index: true, foreign_key: true
      t.text :body
      t.references :path, index: true, foreign_key: true

      t.timestamps null: false
    end
  end
end

I checked and can see my schema in both production and dev match and refer to the last reference in the migration files. But when

When I use rails console production, I can see that the comments table is not there. Here is the message in my console.

Loading production environment (Rails 4.2.5)
2.2.1 :001 > Comment.all
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "comments" does not exist
LINE 1: SELECT "comments".* FROM "comments"
                                 ^
: SELECT "comments".* FROM "comments"
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/querying.rb:39:in `find_by_sql'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:639:in `exec_queries'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:515:in `load'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:243:in `to_a'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:630:in `inspect'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:45:in `require'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:45:in `block in exec_app_rails'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:34:in `loop'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:34:in `exec_app_rails'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/cli.rb:5:in `<top (required)>'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/bin/rails:9:in `require'
    from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/bin/rails:9:in `<top (required)>'
    from /home/laurie/.rvm/gems/ruby-2.2.1/bin/rails:23:in `load'
    from /home/laurie/.rvm/gems/ruby-2.2.1/bin/rails:23:in `<main>'
    from /home/laurie/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
    from /home/laurie/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'2.2.1 :002 > 

I have tried sudo-apt-get clean as well, I have reset my databases, added the action-pack caching gems and restarted my server several times.

My production log lists the comments view files which aren't rendering (because there is no comments table).

Running rake db:migrate:status shows "no file"

up     20151224215110  Devise create users
up     20151231173736  Add first name last name to users
up     20160112022120  Add role to users
up     20160122204744  Create paths
up     20160123004558  Add attachment image to paths
up     20160124191428  Remove user id from paths
up     20160124191601  Add user id to paths
up     20160124212622  Remove bio from users
up     20160124213023  Add bio to users
up     20160124213311  Remove title from paths
up     20160124213624  Add title content to paths
up     20160204222816  ********** NO FILE **********

checking the directory (production server) I see the file is not there.

Also, deleted old migrations, checked my server for memory, etc. Coming up blank?

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Laurie
  • 162
  • 1
  • 11

1 Answers1

0

I know that his is a silly question, but are you using the console with the production environment?

RAILS_ENV=production rails c
Eduardo
  • 74
  • 1
  • 9
  • Or what ever env you have on your Digital Ocean machine. – Eduardo Feb 05 '16 at 02:30
  • Also, this can be b/c you didn't make push of the last commit (the one that have the migration), you can verify if you push to the branch that capistrano is using to obtain the code in the server. I just guessing :( – Eduardo Feb 05 '16 at 02:34
  • Not a silly question. Yes, I was in my production server, and checked the console first in development, then in production. I used rails c production.. – Laurie Feb 05 '16 at 02:36
  • I am running on Ubuntu 14.04 – Laurie Feb 05 '16 at 02:38
  • I think this question is related, did you check it? http://stackoverflow.com/questions/16041790/what-is-the-best-way-to-resolve-rails-orphaned-migrations – Eduardo Feb 05 '16 at 02:41
  • I am trying this forum, incase there is an issue with my Postgres settings. https://help.ubuntu.com/community/PostgreSQL Will update if I find anything – Laurie Feb 05 '16 at 02:55
  • I am still having the same problem. I noticed that the comment migration file (the missing one) is not in my bitbucket repository. I'm not sure why. Even after rollback, I seem to get the same result. – Laurie Feb 05 '16 at 05:53
  • Fixed it!!! added the migration.rb file directly into my repository and redeployed. Thanks for the link Eduardo, that helped - $ rails dbconsole then .. add to schema_migrations where version=''; – Laurie Feb 05 '16 at 08:27
  • Excellent! I'm glad to hear that :) – Eduardo Feb 05 '16 at 16:26