Using my brand new enki blog instance with a SQLite database, I wrote my first post… then I told myself that it could be nice to use a PostgreSQL database, just for fun…
Google and a stackoverflow entry gives me the answer, here the step-by-step result for a RAILS_ENV="production"
:
- Install PostgreSQL (see my previous post Postgresql installation on debian Wheezy)
$ cp config/database.yml config.database.yml.sqlite3
- Install yaml_db:
$ sudo gem install yaml_db
and add that gem to your Gemfile - Add the PostgreSQL support:
$ sudo gem install pg
and add that gem to your Gemfile - Add a new
config/database.yml.pg
file:
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 |
|
- Backup your SQLite data with yaml_db:
$ rake db:dump RAILS_ENV="production"
- Configure Rails to use your new PostgreSQL configuration:
$ cp config/database.yml.pg config/database.yml
- Create the database and the associated tables:
$ rake db:create RAILS_ENV="production"
- Load your schema:
$ rake db:schema:load RAILS_ENV="production"
- Load your data with yaml_db:
$ rake db:load RAILS_ENV="production"
Et voilà !