Setting Up Postgre 9.1 for Rails Development

I am using rails to build www.mes-courses.fr. I use ubuntu for my development os, and heroku for deployment. As heroku enforces the usage of Postgre, I chose to use Postgre on my development setup also. When I upgraded from ubuntu 10.04, I had to review my database configuration.

I have a script in script/setup that installs dependencies and databases to setup a new dev environment :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh

## packages dependencies
 sudo apt-get install libxml2-dev libxslt1-dev postgresql libpq-dev sqlite3 libsqlite3-dev

## installing gems
 bundle install   rbenv rehash

## creating dbs
 sudo -u postgres createuser --superuser mes_courses
 sudo -u postgres psql --command="alter user mes_courses with encrypted password 'secret'"
 sudo sed -i 's/\(local *all *all *\)peer/\1md5/' /etc/postgresql/9.1/main/pg_hba.conf
 bundle exec rake db:create:all

## initializing dbs
 bundle exec rake db:migrate
 RAILS_ENV=test bundle exec rake db:migrate
 RAILS_ENV=production bundle exec rake db:migrate

Here is the corresponding config/database.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
development:
 adapter: postgresql
 database: mes_courses_development
 encoding: utf8
 pool: 5
 timeout: 5000
 username: mes_courses
 password: secret
 host: localhost
 port: 5433

test:
 adapter: postgresql
 database: mes_courses_test
 encoding: utf8
 pool: 5
 timeout: 5000
 username: mes_courses
 password: secret
 host: localhost
 port: 5433

production:
 adapter: postgresql
 database: mes_courses_production
 encoding: utf8
 pool: 5
 timeout: 5000
 username: mes_courses
 password: secret
 host: localhost
 port: 5433

Hope this helps !

Comments