Rails 3から3.1に移行し、Herokuで動作させる方法についてのドキュメントをフォローしています。ここに記載されている手動アップグレード手法を使用しました:http ://webtempest.com/upgrade-rails-3-to-3-1/
少しずつ進歩しましたが、Herokuで動作させるのはほとんど苦痛でした。私のアプリケーションは、現時点ではrails3.1でローカルに正常に動作します。開発モードでは、mysqlを使用していることをお知らせする必要があります(単に、sequel proを使用するオプションがあり、postgresをローカルで使用する方法をまだ完全に理解していないためです)。つまり、Rails 3.0を使用しているときに、アプリをherokuにプッシュし、postgresおよびローカルでmysqlで使用することに問題はありませんでした。それは常にうまくいきました。ただし、heroku cedarスタックを使用して3.1に移行したので、herokuのドキュメントをフォローしているときに次の問題が発生します:http://devcenter.heroku.com/articles/rails31_heroku_cedar
以下は、コードをherokuにプッシュした後、アプリケーションのデータベースを移行またはリセットしようとしたとき、およびアプリケーションを再起動したときに発生し続けるエラーです。
Running rake db:reset attached to terminal... up, run.9
Couldn't drop hvifyyqdjs : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database hvifyyqdjs
: DROP DATABASE IF EXISTS "hvifyyqdjs">
hvifyyqdjs already exists
rake aborted!
PGError: ERROR: relation "users" does not exist
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
この問題を克服する方法について何かアイデアはありますか?ここで言及されている「ユーザー」用のdeviseプラグインを使用しています。この問題に関する私の調査により、以前は、移行によってユーザーテーブルが適切に作成されなかった可能性があると考えていましたが、最初の移行ファイルではユーザーテーブルが作成されます。
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# t.encryptable
# t.confirmable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
drop_table :users
end
end
herokuでアプリを再起動しようとすると、これがログに表示されます
2011-09-28T09:55:08+00:00 app[web.1]: => Booting WEBrick
2011-09-28T09:55:08+00:00 app[web.1]: => Rails 3.1.0 application starting in production on http://0.0.0.0:33603
2011-09-28T09:55:08+00:00 app[web.1]: => Call with -d to detach
2011-09-28T09:55:08+00:00 app[web.1]: => Ctrl-C to shutdown server
2011-09-28T09:55:08+00:00 app[web.1]: Exiting
2011-09-28T09:55:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:962:in `async_exec': PGError: ERROR: relation "users" does not exist (ActiveRecord::StatementInvalid)
2011-09-28T09:55:08+00:00 app[web.1]: : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
2011-09-28T09:55:08+00:00 app[web.1]: FROM pg_attribute a LEFT JOIN pg_attrdef d
2011-09-28T09:55:08+00:00 app[web.1]: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
2011-09-28T09:55:08+00:00 app[web.1]: WHERE a.attrelid = '"users"'::regclass
2011-09-28T09:55:08+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped
2011-09-28T09:55:08+00:00 app[web.1]: ORDER BY a.attnum
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:962:in `exec_no_cache'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:551:in `block in exec_query'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:550:in `exec_query'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1061:in `column_definitions'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:740:in `columns'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `block in initialize'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `yield'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `default'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:706:in `columns'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:722:in `column_names'
2011-09-28T09:55:08+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base
ヘルプ、提案、ヒントは大歓迎です。