Skip to content

Instantly share code, notes, and snippets.

@satomixx
Last active August 29, 2015 14:17
Show Gist options
  • Save satomixx/2b6d60dbf04a07a91a9d to your computer and use it in GitHub Desktop.
Save satomixx/2b6d60dbf04a07a91a9d to your computer and use it in GitHub Desktop.
MacOSX YosemiteでRails4.xを動かして、Postgresと繋げるときのメモ ref: http://qiita.com/tsumekoara/items/1c19052360864204c4f1
default: &default
# adapter: mysql2
adapter: postgresql
encoding: utf8
pool: 5
# username: root
username: hoge
password:
# socket: /tmp/mysql.sock
development:
<<: *default
database: hoge_development
test:
<<: *default
database: hoge_test
production:
<<: *default
database: hoge_production
password: <%= ENV['HOGE_DATABASE_PASSWORD'] %>
postgres=# create role hoge createdb replication superuser createrole login
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
hoge | Superuser, Create role, Create DB, Replication | {}
$ rake db:create
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "username"=>"hoge", "password"=>nil, "database"=>"hoge_development"}
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "matcha_test" ENCODING = 'utf8'
$ sudo -u postgres -iPassword:
postgres$ psql
psql (9.4.1, server 9.4.0)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------------+----------+----------+---------+-------+-----------------------
hoge_development | hoge | UTF8 | C | C |
hoge_test | hoge | UTF8 | C | C |
$ psql -U hoge -d hoge_development
psql (9.4.1, server 9.4.0)
Type "help" for help.
hoge_development=>
$ rails dbpsql (9.4.1, server 9.4.0)
Type "help" for help.
hoge_development=>
$ rake db:migrate
$ rails s
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
bin/rails:6: warning: already initialized constant APP_PATH
/Users/hoge/bin/rails:6: warning: previous definition of APP_PATH was here
Usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
In addition to those, there are:
destroy Undo code generated with "generate" (short-cut alias: "d")
plugin new Generates skeleton for developing a Rails plugin
runner Run a piece of code in the application environment (short-cut alias: "r")
All commands can be run with -h (or --help) for more information.
$ rake rails:update:bin
$ bin/spring binstub --remove --all
# GemfileからSpringの部分をコメントアウトして
$ bundle install
$ rails db
psql: FATAL: role "hoge" does not exist
$ sudo su - postgres
or
$ sudo -u postgres -i
postgres$ psql
psql (9.4.1, server 9.4.0)
Type "help" for help.
postgres-# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
#gem 'mysql2'
gem 'pg'
gem 'rails_12factor', group: :production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment