Aug
10
2008
Making (and Verifying) the Migration to PostgreSQL in Rails
Posted by Chirag Patel in Insights at 12:47 AMInstall
After installing PostgreSQL on Windows, I converted my Rails application from MySQL to PostgreSQL with the following steps:
- Create a new database in PostgreSQL
- Installed
postgres-prgem (Ruby driver) because thepostgresgem (native driver) didn’t work. Will figure out why later on. - Changed the appropriate Rails config stuff in
database.ymldevelopment: adapter: postgresql database: database_name username: postgres password: password host: localhost
- I ran only my first Rails migration to test that it worked using this command:
rake db:migrate VERSION=1. My first migration (001_create_heartrates.rb) creates a table in the database so it will be easy to test.
Robby explains a quick way to migrate the data as well
Test
You can test that the migration worked via 2 methods (GUI or command line)
- Using following commands with the
psqlcommand line utility (Start Menu -> PostgreSQL -> psql to postgres):
psql commmand Description \?help \c database_nameconnect to a database (many other commands won’t work until you execute this) \dtshow tables (execute \cfirst)\d table_namedescribes a particular table (e.g. table_name) - Using the pgAdmin III GUI:
- The database table is deeply nested in the tree, I missed it at first. Go to
PostgreSQL Database Server 8.2 -> Databases -> database_name -> Schemas -> public -> Tables -> table_name
- The database table is deeply nested in the tree, I missed it at first. Go to
Related posts:
- Create Ruby Migration To Add An Index To A PostgreSQL Table The other day I did some optimization work on a...
- How to Dump the Data From One PostgreSQL Table Below is the command to use when you would like...
- Create and Delete a PostgreSQL Database from PSQL CLI Easily create or drop a database via the psql CLI...
- Shell Script To Configure A Read Only User On A PostgreSQL Database **UPDATE: New article here. Its a little more complicated to...
- Export PostgreSQL Table Data To Excel CSV File From PSQL CLI When working on a project where I was required to...
Tags: database, migration, nested, pgAdmin, postgres-pr, PostgreSQL, psql, rails, ruby on rails, schemas, table, utility
























Entries (RSS)