RoR: Setting up Postgres
One week in and still stumbling slowly along.
Setting up Postgres with Rails on Windows
- Install PostgreSQL. I used the One Click Installer. Version 8.3, at the moment. I left all the default settings, including the default user postgres.
- Install the Ruby Postgres driver so that it can talk to the database. From the Ruby console:
gem install postgres-pr. - Add Postgres \bin to the PATH environment variable so that Windows will know where to find the program when you’re trying to execute a Postgres command:
Start > Settings > Control Panel > System > Advanced > Environment Variables > PATH > edit. Append the path to the Postgres \bin to the end of the value.
Talking to Postgres
- Specifying the database option (e.g.
rails -d Postgres appName) when you’re creating a new Rails application will configure database.yml with the correct adapter. Otherwise, it’s just a matter of changing the adapter value from sqlite or mysql to postgresql. Similarly, migrating for an existing application will only require changing the settings in database.yml. - Set up the databases. This can be done either through the command line of through the pgAdmin III, the GUI admin panel that comes with PostgresSQL.
- Using the command-line:
Start > Programs > PostgreSQL 8.3 > SQL Shell- Answer the prompts until you’re connected to the server.
CREATE DATABASE db_name;adhere Rails convention to create and name the 3 databases. If successful,CREATE DATABASEwill echo back at you.
- Using the GUI:
Start > Programs > PostgreSQL 8.3 > pgAdmin III- Double click on the PostgreSQL server under the Object Browser on the left, and you’ll be prompted for your password.
- Right click for New Database…: Stick to all the default settings.
- Using the command-line:
- Migrate the application tables. Restart the web server, and on the Ruby Console:
rake db:migrate. - Verify that the migration was successful:
- Using the command-line SQL shell
- While you’re still logged in on the server, connect to your database:
\c db_name. - Do
\dtto list the tables that should have been created during the migration.
- While you’re still logged in on the server, connect to your database:
- Using the GUI
- The tables should be under
Servers > PostgreSQL 8.3 > Databases > db_name > Schemas > public > tables.
- The tables should be under
- Using the command-line SQL shell
Helpful Links
Comments
Setting Up Postgresql with Rails on Windows (August 13th, 2009, 1:52 pm):
[…] Sensorial’Org] Tags: howto, installation, installing, postgresql, rails, ror, rubyonrails, […]
Leave a Comment
January 12th, 2009
6:11 pm
Filed under 'Development, OLM'