Friday, May 20, 2011

Switching to PostgreSQL in Netzke Demo

I have successfully installed Netzke on my Ubuntu, but it uses MySQL. I want to use PostgreSQL.

1. Resources.
Netzke homepage: http://netzke.org/
Netzke demo code: https://github.com/skozlov/netzke-demo
My Installation experience: http://socrateos.blogspot.com/2011/05/installing-netzke-demo-app-on-ubuntu.html
A Solution to 'rake aborted! no such file to load — pg' error: http://www.petermac.com/rubyrails-3-and-postgresql/

2. Edit the config\database.yml file.
adapter: postgresql    # was: mysql2
username: postgres     # was: root
host: localhost        # was: socket: /var/run/mysqld/mysqld.sock

3. Create Database and Migrate for PostgreSQL.
But I got an error saying "no such file to load -- pg" even though I have pg installed and can be loaded, for example, in irb.
$ rake db:create && rake db:migrate
rake aborted!
no such file to load -- pg
....
$ gem list --local

*** LOCAL GEMS ***

...
pg (0.11.0)
...
$ irb
ruby-1.9.2-p180 :001 > require 'pg'
 => true 
ruby-1.9.2-p180 :002 > 

4. A solution to the problem: "no such file to load -- pg"
Thanks to Peter Mac Giollafhearga, there is a simple solution. You have to edit Gemfile, replacing mysql2 with pg.
source 'http://rubygems.org'

gem 'rails', '3.0.4'

gem 'pg'    # was: 'mysql2'

gem 'haml'

gem 'coderay'
gem 'faker'

gem 'netzke-core',        :path => File.expand_path('../vendor/gems/netzke-core', __FILE__)
gem 'netzke-basepack',    :path => File.expand_path('../vendor/gems/netzke-basepack', __FILE__)
gem 'netzke-persistence', :path => File.expand_path('../vendor/gems/netzke-persistence', __FILE__)

gem 'carrierwave'

gem 'inploy'

gem 'will_paginate', '~>3.0.pre2'

group :profiling do
  gem 'rack-perftools_profiler', '~> 0.1', :require => 'rack/perftools_profiler'
end

5. Try again to Crate Database and Migrate for PostgreSQL.
$ rake db:create && rake db:migrate
This time, it worked.

6. Launch the Server and See the Result.
$ rails s
=> Booting WEBrick
=> Rails 3.0.4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-05-19 20:59:37] INFO  WEBrick 1.3.1
[2011-05-19 20:59:37] INFO  ruby 1.9.2 (2011-02-18) [i686-linux]
[2011-05-19 20:59:37] INFO  WEBrick::HTTPServer#start: pid=8030 port=3000

No comments:

Post a Comment