読了: 約 8 分
表題の通りですが、defaultはsqlite3が入っているrailsですが、最初からpostgresqlを入れてherokuにdeployする際に発生した問題についてメモ
herokuのdev centerにdefaultの設定方法とか詳細書いてあるので、そちらを参照して頂きたいのですが、
新規のrailsアプリ立ち上げの際にdefaultのdbをpostgreに設定する
$ rails new projectname -d postgresql
そうすると下記の様にデフォルトでconfig/database.yml
の設定が変化します。
development: adapter: postgresql encoding: unicode database: no-cancel_development pool: 5 username: no-cancel password: # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. #host: localhost #port: 5432 # Schema search path. The server defaults to $user,public #schema_search_path: myapp,sharedapp,public # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic # The server defaults to notice. #min_messages: warning # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: postgresql encoding: unicode database: no-cancel_test pool: 5 username: no-cancel password: production: adapter: postgresql encoding: unicode database: no-cancel_production pool: 5 username: no-cancel password:
gemfile
も上記コマンドで生成した場合は下記のようにpg
になっています。
//gemfile gem 'pg'
databaseの名前は上記で設定した際のprojectname_development,_test等のようになっています。
ここまででpostgreの設定は終了
db作成でのエラー対応
$ rake db:create $ rake db:migrate
上記のコマンドを打つとエラーが下記のように出ます。
しかしdbディレクトリは存在しています。
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
そこで一応再確認
$ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
解決としては一旦postgreをデフォルトでsetするのをやめてgemfileで分岐するようにしました。
productionはpgでdevelopmentはsqlite3という事で。
それでまぁ無事に動いたようなのでこれからごりごり開発して行きます。
$ git push heroku master Counting objects: 9, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 738 bytes | 0 bytes/s, done. Total 6 (delta 4), reused 0 (delta 0) -----> Ruby app detected -----> Compiling Ruby/Rails -----> Using Ruby version: ruby-2.0.0 -----> Installing dependencies using Bundler version 1.3.2 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment Fetching gem metadata from https://rubygems.org/.......... Fetching gem metadata from https://rubygems.org/.. Using rake (10.1.0) Using i18n (0.6.9) Using multi_json (1.8.2) Using activesupport (3.2.12) Using builder (3.0.4) Using activemodel (3.2.12) Using erubis (2.7.0) Using journey (1.0.4) Using rack (1.4.5) Using rack-cache (1.2) Using rack-test (0.6.2) Using hike (1.2.3) Using tilt (1.4.1) Using sprockets (2.2.2) Using actionpack (3.2.12) Using mime-types (1.25.1) Using polyglot (0.3.3) Using treetop (1.4.15) Using mail (2.4.4) Using actionmailer (3.2.12) Using arel (3.0.3) Using tzinfo (0.3.38) Using activerecord (3.2.12) Using activeresource (3.2.12) Using coffee-script-source (1.6.3) Using execjs (2.0.2) Using coffee-script (2.2.0) Using rack-ssl (1.3.3) Using json (1.8.1) Using rdoc (3.12.2) Using thor (0.18.1) Using railties (3.2.12) Using coffee-rails (3.2.2) Using jquery-rails (3.0.4) Using pg (0.17.0) Using bundler (1.3.2) Using rails (3.2.12) Installing rails_serve_static_assets (0.0.1) Installing rails_stdout_logging (0.0.3) Installing rails_12factor (0.0.2) Using sass (3.2.12) Using sass-rails (3.2.6) Using uglifier (2.3.2) Your bundle is complete! It was installed into ./vendor/bundle Bundle completed (8.14s) Cleaning up the bundler cache. -----> Writing config/database.yml to read from DATABASE_URL -----> Preparing app for Rails asset pipeline Running: rake assets:precompile Running: rake assets:precompile Compiled jquery.js (4ms) (pid 717) Compiled jquery_ujs.js (0ms) (pid 717) Compiled application.js (14ms) (pid 717) Compiled application.css (1ms) (pid 717) Compiled jquery.js (4ms) (pid 717) Compiled jquery_ujs.js (0ms) (pid 717) Compiled application.js (14ms) (pid 717) Compiled application.css (1ms) (pid 717) Asset precompilation completed (10.82s) -----> WARNINGS: You have not declared a Ruby version in your Gemfile. To set your Ruby version add this line to your Gemfile: ruby '2.0.0' # See https://devcenter.heroku.com/articles/ruby-versions for more information. -----> Discovering process types Procfile declares types -> (none) Default types for Ruby -> console, rake, web, worker -----> Compiled slug size: 21.0MB -----> Launching... done, v6