PostgreSQL
 SQL >> Database >  >> RDS >> PostgreSQL

Configurare PostgreSQL per Ruby on Rails su Ubuntu

Questa è la sequenza di passaggi che permette a un'app Rails di comunicare con un server PostgreSQL locale su Ubuntu.

Installa il server e gli header

$ sudo apt-get install postgresql $ sudo apt-get install libpq-dev 

Il pacchetto libpq-dev è ciò che consente alla gemma pg di compilare.

Crea un ruolo corrispondente al tuo login

$ sudo su postgres -c psql postgres=# CREATE ROLE <username> SUPERUSER LOGIN; postgres=# \q 

Cambia l'adapter del database nel Gemfile

# Remove gem 'sqlite3' gem 'pg' 

Punta database.yml a PostgreSQL

development: adapter: postgresql encoding: unicode database: appname_development pool: 5 timeout: 5000 username: <username> password: test: adapter: postgresql encoding: unicode database: appname_test pool: 5 timeout: 5000 username: <username> password: 

Installa le gemme, crea i database, esegui le migrazioni

$ bundle install $ rake db:create:all $ rake db:migrate 

Riferimenti utili lungo il percorso:

https://mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
https://railscasts.com/episodes/342-migrating-to-postgresql
https://devcenter.heroku.com/articles/local-postgresql