<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag postgresql</title>
    <link>http://www.robbyonrails.com/articles/tag/postgresql</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Installing Ruby on Rails and PostgreSQL on OS X, Third Edition</title>
      <description>&lt;p&gt;Over the past few years, I&amp;#8217;ve helped you walk through the process of getting Ruby on Rails up and running on Mac &lt;span class="caps"&gt;OS X&lt;/span&gt;. The last version has been getting a lot of comments related to issues with the new Apple Leopard, so I&amp;#8217;m going this post will expand on previous installation guides with what&amp;#8217;s working for me as of January 2008.&lt;/p&gt;


	&lt;p&gt;The following guide is how our development team at &lt;a href="http://planetargon.com"&gt;Planet Argon&lt;/a&gt; prefers to setup our development workstations&lt;/p&gt;


	&lt;p&gt;During this installation, we&amp;#8217;ll have what we feel is the optimal development stack for building &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt; applications with our favorite database server, &lt;a href="http://postgresql.org"&gt;PostgreSQL&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Ready? Let&amp;#8217;s get started&amp;#8230;&lt;/p&gt;
&lt;h2&gt;Phase One&lt;/h2&gt;


	&lt;p&gt;During this initial phase, we&amp;#8217;re going to install the underlying dependencies that we&amp;#8217;ll be building off of.&lt;/p&gt;


	&lt;h3&gt;XCode 3.0&lt;/h3&gt;


	&lt;p&gt;The first thing that you&amp;#8217;ll need to install to get far with this process is XCode tools, which is distributed by Apple. You can find this on the &lt;span class="caps"&gt;DVD&lt;/span&gt; that your Leopard installer is on. You can also download the latest version from Apple&amp;#8217;s developer site.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://developer.apple.com/tools/download/"&gt;http://developer.apple.com/tools/download/&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The current version (3.0) is 1.1 GB.. so the download time will vary depending on your connection speed. I would encourage you to drink some tea and/or &lt;a href="http://www.amazon.com/gp/product/0684868768?ie=UTF8&amp;#38;tag=robonrai-20&amp;#38;linkCode=as2&amp;#38;camp=1789&amp;#38;creative=9325&amp;#38;creativeASIN=0684868768"&gt;read a book&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=robonrai-20&amp;#38;l=as2&amp;#38;o=1&amp;#38;a=0684868768" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;/p&gt;


	&lt;p&gt;Once you finish the installation, you can move forward. The rest of these installation &lt;strong&gt;will not work&lt;/strong&gt; until XCode is installed. :-)&lt;/p&gt;


	&lt;h3&gt;MacPorts&lt;/h3&gt;


	&lt;p&gt;In this next step, we&amp;#8217;ll install &lt;a href="http://www.macports.org/"&gt;MacPorts&lt;/a&gt; (formerly known as DarwinPorts). The MacPorts web site describes itself as, &lt;em&gt;&amp;#8220;an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, &lt;span class="caps"&gt;X11&lt;/span&gt; or Aqua based open-source software on the Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; operating system.&amp;#8221;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080122-jxqkyy8hc8ug7qxy4jt6qeg3d1.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;This tool is about to become one of the most important tools on your operating system as it&amp;#8217;ll be used time and time again to maintain your libraries and many of the Unix tools that you&amp;#8217;ll be using. If you’re from the Linux or &lt;span class="caps"&gt;BSD&lt;/span&gt; world, you are likely familiar with similar tools… such as: apt-get, port, and yum.&lt;/p&gt;


	&lt;p&gt;First, you&amp;#8217;ll want to download MacPorts and install the &amp;#8220;dmg&amp;#8221; disk file for Leopard at the following link.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.macports.org/install.php"&gt;http://www.macports.org/install.php&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Once downloaded, you&amp;#8217;ll want to run the installer and install it on your workstation.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdqg/install-macports-1.6.0"&gt;&lt;img src="http://img.skitch.com/20080122-efm4gb9pbb79p4ujya1ceisn37.preview.jpg" alt="Install MacPorts-1.6.0" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;Work you way through the installer until successfully installed.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdqe/install-macports-1.6.0"&gt;&lt;img src="http://img.skitch.com/20080122-rr9e1begkg73ixt11d697wpdfh.preview.jpg" alt="Install MacPorts-1.6.0" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;Once this finishes, you can open up your favorite terminal application and run the following to test that it installed properly.&lt;/p&gt;


	&lt;p&gt;In my case, I&amp;#8217;m now using Terminal.app.&lt;/p&gt;


	&lt;p&gt;Issue the command: &lt;code&gt;/opt/local/bin/port version&lt;/code&gt;&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdqm/opt-local-bin-port-version"&gt;&lt;img src="http://img.skitch.com/20080122-piqes1e66rgj1bui7eud9sisf7.preview.jpg" alt="_opt_local_bin_port version" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;If it responds with a version number like mine did in the screenshot above, we&amp;#8217;re moving along nicely.&lt;/p&gt;


	&lt;h3&gt;Environment Paths&lt;/h3&gt;


	&lt;p&gt;When we install MacPorts, the command to install/update ports installed to &lt;code&gt;/opt/local/bin&lt;/code&gt;. We had to provide the entire path as this isn&amp;#8217;t currently showing up in the default &lt;code&gt;$PATH&lt;/code&gt; on Leopard. Let&amp;#8217;s quickly remedy this by modifying the file &lt;code&gt;/etc/profile&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;If you have Textmate installed, you can run the following from your terminal: &lt;code&gt;mate /etc/profile&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Add the following line to the bottom of &lt;code&gt;/etc/profile&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;export PATH=/opt/local/bin:/opt/local/sbin:$PATH&lt;/code&gt;&lt;/pre&gt;

&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdxb/profile"&gt;&lt;img src="http://img.skitch.com/20080122-mqk8awqpbeebmdq7p7r1gyixsy.preview.jpg" alt="profile" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;You can use your favorite editor to update this file. Once you save it, you&amp;#8217;ll want to restart your terminal application (or open a new tab) to create a new session. When your new terminal opens, run the following to verify that &lt;code&gt;port&lt;/code&gt; is showing up in your &lt;code&gt;$PATH&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;which port&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;You should see &lt;code&gt;/opt/local/bin/port&lt;/code&gt; show up as the result of this command.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdx8/which-port"&gt;&lt;img src="http://img.skitch.com/20080122-d4hte4cm5gn67a4cum26gbibut.preview.jpg" alt="which port" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;Great, let&amp;#8217;s continue to move forward.&lt;/p&gt;


	&lt;h3&gt;Hiding Apple&amp;#8217;s Ruby, Gems, and Rails&lt;/h3&gt;


	&lt;p&gt;Before we install Ruby from MacPorts, we&amp;#8217;ll go ahead and hide Apple&amp;#8217;s Ruby installations.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    :~ robbyrussell$ sudo su -
    Password:
    :~ root# mv /usr/bin/ruby /usr/bin/ruby.orig
    :~ root# mv /usr/bin/gem /usr/bin/gem.orig
    :~ root# mv /usr/bin/rails /usr/bin/rails.orig
    :~ root# logout    
&lt;/code&gt;&lt;/pre&gt;

&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/fdxe/hiding-apples-ruby"&gt;&lt;img src="http://img.skitch.com/20080122-rgmsuy746h73b1bc93j4nyi5ar.preview.jpg" alt="hiding apples ruby" /&gt;&lt;/a&gt;&lt;/div&gt;

	&lt;p&gt;If you ever decide to remove MacPorts, you can just rename &lt;code&gt;ruby.orig&lt;/code&gt; back to &lt;code&gt;ruby&lt;/code&gt; and you&amp;#8217;re back where you started&amp;#8230; and the same for the others listed.&lt;/p&gt;


	&lt;h2&gt;Phase Two&lt;/h2&gt;


	&lt;p&gt;During this next phase, we&amp;#8217;re going to install Ruby and Ruby on Rails.&lt;/p&gt;


	&lt;h3&gt;Installing Ruby via MacPorts&lt;/h3&gt;


	&lt;p&gt;Now that we have MacPorts up and running, we&amp;#8217;re going to use it for the first time. We&amp;#8217;ll start by using it to install Ruby and the Rubygems package.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo port install ruby rb-rubygems&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Okay, this will take a little while. I&amp;#8217;d suggest that you step out to get some fresh air.&lt;/p&gt;


	&lt;p&gt;How was it outside? What&amp;#8217;s the weather like there today? It&amp;#8217;s currently 2:30am &lt;span class="caps"&gt;PST&lt;/span&gt; so it&amp;#8217;s dark and an 28F outside so I didn&amp;#8217;t stay outside very long.&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re still waiting for it to install, perhaps you could watch the following video. I might encourage you to check out more of &lt;a href="http://en.wikipedia.org/wiki/Jam_%28TV_series%29"&gt;Jam&lt;/a&gt;, which was recommended a few years ago to me by &lt;a href="http://interblah.net/"&gt;James Adam&lt;/a&gt; at &lt;a href="http://www.canadaonrails.org/"&gt;Canada on Rails&lt;/a&gt;.&lt;/p&gt;


&lt;object width="425" height="355"&gt;&lt;param name="movie" value="http://www.youtube.com/v/sLD0SNCFtyA&amp;#38;rel=1"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/sLD0SNCFtyA&amp;#38;rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;

	&lt;p&gt;Be warned&amp;#8230; it&amp;#8217;s a strange show, but I find strange things like this funny. :-)&lt;/p&gt;


	&lt;p&gt;If you prefer something a bit more lighthearted&amp;#8230;&lt;/p&gt;


&lt;object width="425" height="355"&gt;&lt;param name="movie" value="http://www.youtube.com/v/SO5WoLnOOlU&amp;#38;rel=1"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/SO5WoLnOOlU&amp;#38;rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;

	&lt;p&gt;Okay&amp;#8230; when Ruby finishes installing, you&amp;#8217;ll want to test that you can run it.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ ruby -v&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, let&amp;#8217;s move forward!&lt;/p&gt;


	&lt;h3&gt;Installing Ruby on Rails via RubyGems&lt;/h3&gt;


	&lt;p&gt;We&amp;#8217;re now going to install the libraries that make up Ruby on Rails via RubyGems.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo gem install --include-dependencies rails&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This will install the following gems.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;rails-2.0.2&lt;/li&gt;
		&lt;li&gt;rake-0.8.1&lt;/li&gt;
		&lt;li&gt;activesupport-2.0.2&lt;/li&gt;
		&lt;li&gt;activerecord-2.0.2&lt;/li&gt;
		&lt;li&gt;actionpack-2.0.2&lt;/li&gt;
		&lt;li&gt;actionmailer-2.0.2&lt;/li&gt;
		&lt;li&gt;activeresource-2.0.2&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Excellent, let&amp;#8217;s move forward&amp;#8230;&lt;/p&gt;


	&lt;p&gt;If you haven&amp;#8217;t already purchased it, I recommend that you take a look at &lt;a href="http://www.amazon.com/gp/product/0321445619?ie=UTF8&amp;#38;tag=robonrai-20&amp;#38;linkCode=as2&amp;#38;camp=1789&amp;#38;creative=9325&amp;#38;creativeASIN=0321445619"&gt;The Rails Way (Addison-Wesley Professional Ruby Series)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=robonrai-20&amp;#38;l=as2&amp;#38;o=1&amp;#38;a=0321445619" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt; by Obie Fernandez.&lt;/p&gt;


	&lt;h3&gt;Installing Mongrel via RubyGems&lt;/h3&gt;


	&lt;p&gt;Let&amp;#8217;s now install Mongrel, which is an excellent Ruby-based web server for Ruby on Rails applications. We use it in development and production at &lt;a href="http://planetargon.com"&gt;Planet Argon&lt;/a&gt; and it&amp;#8217;s also what we recommend to our &lt;a href="http://planetargon.com/hosting.html"&gt;hosting customers&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo gem install --include-dependencies mongrel mongrel_cluster&lt;/code&gt;&lt;/pre&gt;

	&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt; Be sure to select the proper platform for mongrel. (hint: &lt;span class="caps"&gt;OS X&lt;/span&gt; is &lt;span class="caps"&gt;NOT&lt;/span&gt; mswin32)&lt;/li&gt;
	&lt;/ul&gt;


My terminal output:
&lt;pre&gt;&lt;code&gt;
Select which gem to install for your platform (i686-darwin9.1.0)
 1. mongrel 1.1.3 (java)
 2. mongrel 1.1.3 (i386-mswin32)
 3. mongrel 1.1.3 (ruby)
 4. mongrel 1.1.2 (ruby)
 5. mongrel 1.1.2 (mswin32)
 6. mongrel 1.1.2 (java)
 7. Skip this gem
 8. Cancel installation
&amp;gt; 3
Select which gem to install for your platform (i686-darwin9.1.0)
 1. fastthread 1.0.1 (mswin32)
 2. fastthread 1.0.1 (ruby)
 3. Skip this gem
 4. Cancel installation
&amp;gt; 2
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed mongrel-1.1.3
Successfully installed gem_plugin-0.2.3
Successfully installed daemons-1.0.9
Successfully installed fastthread-1.0.1
Successfully installed cgi_multipart_eof_fix-2.5.0
Installing ri documentation for mongrel-1.1.3...
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for daemons-1.0.9...
Installing ri documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing ri documentation for cgi_multipart_eof_fix-2.5.0...
Installing RDoc documentation for mongrel-1.1.3...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for daemons-1.0.9...
Installing RDoc documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing RDoc documentation for cgi_multipart_eof_fix-2.5.0...
Successfully installed mongrel_cluster-1.0.5
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, you have almost all of the essentials.. except a database.&lt;/p&gt;


	&lt;h2&gt;Phase Three&lt;/h2&gt;


	&lt;p&gt;In this phase, we&amp;#8217;re going to get our database server, PostgreSQL, installed and the libraries that Ruby needs to communicate with it.&lt;/p&gt;


	&lt;h3&gt;Installing PosgreSQL with MacPorts&lt;/h3&gt;


	&lt;p&gt;At &lt;a href="http://planetargon.com"&gt;Planet Argon&lt;/a&gt;, we design and develop our applications on top of &lt;a href="http://postgresql.org"&gt;PostgreSQL&lt;/a&gt;. I’ve been advocating the adoption of this awesome open source database in the Rails community for quite some time now.&lt;/p&gt;


	&lt;p&gt;The current version available of PostgreSQL via MacPorts is 8.3, which is what we&amp;#8217;ll now install with the &lt;code&gt;port&lt;/code&gt; command.&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;$ sudo port install postgresql83 postgresql83-server&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;This will download and install the necessary libraries to run PostgreSQL server and the client utilities.&lt;/p&gt;


	&lt;h3&gt;Configuring PostgreSQL&lt;/h3&gt;


	&lt;p&gt;When PostgreSQL is finished installing, it&amp;#8217;ll tell you to run the following commands to create a new database instance.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
 sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'
&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Adding PostgreSQL to launchd&lt;/h4&gt;


	&lt;p&gt;If you&amp;#8217;d like to have PostgreSQL automatically startup after a system restart, you can load it into launchd, which comes with &lt;span class="caps"&gt;OS X&lt;/span&gt;. By running the following command, PostgreSQL will startup automatically on the next system restart.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Adding PostgreSQL to your $PATH&lt;/h4&gt;


	&lt;p&gt;For some reason, the MacPort for PostgreSQL doesn&amp;#8217;t get the programs in your path automatically, so we&amp;#8217;ll it now.&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;mate /etc/profile&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Modify the &lt;code&gt;PATH&lt;/code&gt; that we changed earlier to include /opt/local/lib/postgresql83/bin@.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql83/bin:$PATH&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Save the file and then open a new terminal. To test this, you should get the following output when you run which &lt;code&gt;psql&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  $ which psql
  /opt/local/lib/postgresql83/bin/psql    
&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Creating a new PostgreSQL user&lt;/h4&gt;


	&lt;p&gt;When I’m working on Rails applications in my development environment, I really don’t want to have to specify a username and password in every &lt;code&gt;config/database.yml&lt;/code&gt; file for each of our ongoing client projects. When PostgreSQL was installed, it created a superuser named &lt;strong&gt;postgres&lt;/strong&gt;, which is great, but I’d like one that matches my system username, so that I’m not prompted at all for a username or password to connect to PostgreSQL.&lt;/p&gt;


	&lt;p&gt;To do this, we’ll use the &lt;code&gt;createuser&lt;/code&gt; command, which comes with PostgreSQL. As you can see, I’m creating a new user with &lt;code&gt;superuser&lt;/code&gt; privileges (and will hopefully be the last time I have to do a &lt;code&gt;-U postgres&lt;/code&gt;).&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  $ createuser --superuser robbyrussell -U postgres
  CREATE ROLE    
&lt;/code&gt;&lt;/pre&gt;

Let’s take a quick moment to test this out.
&lt;pre&gt;&lt;code&gt;
  # create a new database
  $ createdb my_test_db
  CREATE DATABASE

  # drop the database
  $ dropdb my_test_db
  DROP DATABASE
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, everything looks good here.&lt;/p&gt;


	&lt;p&gt;We now have a running installation of PostgreSQL with a new user account. All we need to do now is install the appropriate RubyGem to allow our Ruby applications to connect to it.&lt;/p&gt;


	&lt;h4&gt;Installing PostgreSQL Libraries for Ruby&lt;/h4&gt;


	&lt;p&gt;You can install postgres gem by running the following command.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$  sudo gem install --include-dependencies postgres&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great. We’ve now built a professional development environment for working with Ruby on Rails. Can you &lt;em&gt;feel&lt;/em&gt; the excitement? :-)&lt;/p&gt;


	&lt;h2&gt;Closing Thoughts&lt;/h2&gt;


	&lt;p&gt;Like the previous versions, I hope that a few people find this useful. I didn&amp;#8217;t have to make a lot of changes from the second edition, but there were enough to warrant a new post. I&amp;#8217;ve been setting up my workstation like this for about three years now and I&amp;#8217;m looking forward to seeing how a fresh install on Leopard works out for me.&lt;/p&gt;


	&lt;p&gt;If you have any problems, feel free to ask a question in the comments below.&lt;/p&gt;</description>
      <pubDate>Tue, 22 Jan 2008 11:55:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:73dcd126-1333-417e-9203-aaefb22a65b1</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>PostgreSQL</category>
      <category>PLANET ARGON</category>
      <category>rubyonrails</category>
      <category>rails</category>
      <category>postgresql</category>
      <category>xcode</category>
      <category>apple</category>
      <category>osx</category>
      <category>macports</category>
      <category>ruby</category>
      <category>rubygems</category>
      <category>irb</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>PGCon 2008 - Call for Papers</title>
      <description>&lt;p&gt;Are you using &lt;a href="http://postgresql.org"&gt;PostgreSQL&lt;/a&gt; (the world&amp;#8217;s most awesome open-source database server) with &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;? Do you have any interesting experiences that you might want to share with an audience? Well, you might consider submitting a talk proposal for PGCon 2008, which is taking place in Ottawa, Canada.&lt;/p&gt;


	&lt;p&gt;Details follow&amp;#8230;&lt;/p&gt;


	&lt;h2&gt;PGCon 2008&lt;/h2&gt;


	&lt;p&gt;PGCon 2008 will be held 22-23 May 2008, in Ottawa at the University of
Ottawa.  It will be preceded by two days of tutorials on 20-21 May
2008.&lt;/p&gt;


	&lt;p&gt;We are now requesting proposals for presentations.&lt;/p&gt;


	&lt;p&gt;If you are doing something interesting with PostgreSQL, please submit
a proposal.  You might be one of the backend hackers or work on a
PostgreSQL related project and want to share your know-how with
others. You might be developing an interesting system using
PostgreSQL as the foundation. Perhaps you migrated from another
database to PostgreSQL and would like to share details.  These, and
other stories are welcome. Both users and developers are encouraged
to share their experiences.&lt;/p&gt;


	&lt;p&gt;Here are a few ideas to jump start your proposal process:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;novel, unique or complex ways in which PostgreSQL are used&lt;/li&gt;
		&lt;li&gt;migration of production systems to PostgreSQL&lt;/li&gt;
		&lt;li&gt;data warehousing with PostgreSQL&lt;/li&gt;
		&lt;li&gt;tuning PostgreSQL for different work loads&lt;/li&gt;
		&lt;li&gt;replicating data on top of PostgreSQL&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Both users and developers are encouraged to share their experiences.&lt;/p&gt;


	&lt;p&gt;The schedule is:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;19 Dec 2007 Proposal acceptance begins&lt;/li&gt;
		&lt;li&gt;19 Jan 2008 Proposal acceptance ends&lt;/li&gt;
		&lt;li&gt;19 Feb 2008 Confirmation of accepted proposals&lt;/li&gt;
		&lt;li&gt;19 Apr 2008 Final papers/slides must arrive no later than this date&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;See also &lt;a href="http://www.pgcon.org/2008/papers.php"&gt;http://www.pgcon.org/2008/papers.php&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Instructions for submitting a proposal to PGCon 2008 are available
from: &lt;a href="http://www.pgcon.org/2008/submissions.php"&gt;http://www.pgcon.org/2008/submissions.php&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;This&lt;/p&gt;
</description>
      <pubDate>Fri, 28 Dec 2007 10:58:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:77bc4f6f-b27a-4e11-8298-31a70f57809c</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/12/28/pgcon-2008-call-for-papers</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>PostgreSQL</category>
      <category>postgresql</category>
      <category>ruby</category>
      <category>rubyonrails</category>
      <category>rails</category>
      <category>conference</category>
    </item>
    <item>
      <title>Master/Slave Databases with Ruby on Rails</title>
      <description>&lt;p&gt;Not terribly long ago, I &lt;a href="http://www.robbyonrails.com/articles/2007/10/05/multiple-database-connections-in-ruby-on-rails"&gt;announced Active Delegate&lt;/a&gt;, which was a really lightweight plugin that I developed to allow models to talk to multiple databases for specific methods. The plugin worked great for really simple situations, like individual models.. but when it came time to test with associations it fell apart. I haven&amp;#8217;t had a chance to work on any updates and knew that it was going to take more work to get it going.&lt;/p&gt;


	&lt;p&gt;Earlier this week, we helped one of our bigger clients launch their new web site&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;. For the deployment, we needed to send all writes to a master database and a reads to slaves (initial deployment is talking to almost 10 slaves spread around the globe!). We needed something to get integrated quickly and decided to ditch Active Delegate for the time being and began looking at the following options.&lt;/p&gt;


	&lt;p&gt;I spoke with Rick Olson&lt;sup&gt;&lt;a href="#fn2"&gt;2&lt;/a&gt;&lt;/sup&gt; and he pointed me to a new plugin that he hasn&amp;#8217;t really released yet. So, I&amp;#8217;m going to do him a favor and announce it for him. Of course&amp;#8230; I got his permission first&amp;#8230; ;-)&lt;/p&gt;


	&lt;h2&gt;Announcing Masochism!&lt;/h2&gt;


	&lt;p&gt;Masochism&lt;sup&gt;&lt;a href="#fn3"&gt;3&lt;/a&gt;&lt;/sup&gt; is a new plugin for Ruby on Rails that allows you to delegate all writes to a master database and reads to a slave database. The configuration process is just a few lines in your environment file and the plugin takes care of the rest.&lt;/p&gt;


	&lt;h3&gt;Installing Masochism&lt;/h3&gt;


	&lt;p&gt;With &lt;a href="http://piston.rubyforge.org/usage.html"&gt;piston&lt;/a&gt;, you can import Masochism with:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  $ cd vendor/plugins
  $ piston import http://ar-code.svn.engineyard.com/plugins/masochism/
&lt;/code&gt;&lt;/pre&gt;

	&lt;ul&gt;
	&lt;li&gt;To learn more about piston, read &lt;a href="http://www.robbyonrails.com/articles/2007/01/16/every-second-counts-with-a-piston-in-your-trunk"&gt;Every Second Counts with a Piston in your trunk&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;You can also install it with the old-fashioned way:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  $ ./script/plugin install -x http://ar-code.svn.engineyard.com/plugins/masochism/
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Configuring Masochism&lt;/h3&gt;


	&lt;p&gt;The first thing that you&amp;#8217;ll need to do is add another database connection in &lt;code&gt;config/database.yml&lt;/code&gt; for &lt;code&gt;master_database&lt;/code&gt;. By default, Masochism expects you to have a production database, which will be the read-only/slave database. The &lt;code&gt;master_database&lt;/code&gt; will be the connection details for your (you guessed it&amp;#8230;) master database.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# config/database.yml  
production:
  database: masochism_slave_database
  adapter: postgresql
  host: slavedb1.hostname.tld
  ...

master_database:
  database: masochism_master_database
  adapter: postgresql
  host: masterdb.hostname.tld
  ...
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The idea here is that replication will be handled elsewhere and your application can reap the benefits of talking to the slave database for all of it&amp;#8217;s read-only operations and let the master database(s) spend their time writing data.&lt;/p&gt;


	&lt;p&gt;The next step is to set this up in your environment file. In our scenario, this was &lt;code&gt;config/environments/production.rb&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# Add this to config/environments/production.rb
config.after_initialize do 
  ActiveReload::ConnectionProxy.setup!    
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Voila, you should be good to go now. As I mentioned, we&amp;#8217;ve only been using this for this past week and we&amp;#8217;ve had to address a few problems that the initial version of the plugin didn&amp;#8217;t address. One of our developers, &lt;a href="http://andy.delcambre.com/"&gt;Andy Delcambre&lt;/a&gt;, just posted an article to show how we had a problem with &lt;a href="http://andy.delcambre.com/2007/11/15/masochistic-connection-proxy-with-observers"&gt;using ActiveRecord observers and masochism&lt;/a&gt;, which we&amp;#8217;re sending over a patch for now.&lt;/p&gt;


	&lt;p&gt;As we continue to monitor how this solution works, we&amp;#8217;ll report any findings on our blog. In the meantime, I&amp;#8217;d be interested in knowing what you&amp;#8217;re using to solve this problem. :-)&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; &lt;a href="http://contiki.com"&gt;Contiki&lt;/a&gt;, a cool travel company we&amp;#8217;re working with&lt;/p&gt;


	&lt;p id="fn2"&gt;&lt;sup&gt;2&lt;/sup&gt; Rick just moved to Portland&amp;#8230; welcome to stump town!&lt;/p&gt;


	&lt;p id="fn3"&gt;&lt;sup&gt;3&lt;/sup&gt; &lt;a href="http://ar-code.svn.engineyard.com/plugins/masochism/README"&gt;The Masochism plugin &lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
</description>
      <pubDate>Thu, 15 Nov 2007 16:02:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:3420b2e3-a80c-43c9-a136-a58040069607</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/11/15/master-slave-databases-with-ruby-on-rails</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>plugins</category>
      <category>masochism</category>
      <category>database</category>
      <category>mysql</category>
      <category>postgresql</category>
      <category>client</category>
      <category>development</category>
      <category>activerecord</category>
      <category>replication</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Installing Ruby on Rails and PostgreSQL on OS X, Second Edition</title>
      <description>&lt;p&gt;It&amp;#8217;s been just over a year since I posted the article, &lt;a href="http://www.robbyonrails.com/articles/2006/05/29/install-ruby-rails-and-postgresql-on-osx"&gt;Install Ruby, Rails, and PostgreSQL on &lt;span class="caps"&gt;OSX&lt;/span&gt;&lt;/a&gt; and it still gets quite a bit of traffic. Unfortunately, there have been a few changes in the install process that have caught people.&lt;/p&gt;


	&lt;p&gt;Today, I am leaving my PowerBook G4. It&amp;#8217;s being replaced with a MacBook because the logic board is on the fritz. So, guess what that means? I get to install Ruby, Ruby on Rails, PostgreSQL on &lt;span class="caps"&gt;OS X&lt;/span&gt; again! I figured that I would post a revised version of my previous article for those who may go through this same process in the near future.&lt;/p&gt;


&lt;div class="warning"&gt;
&lt;strong&gt;&lt;span class="caps"&gt;&lt;span class="caps"&gt;WARNING&lt;/span&gt;&lt;/span&gt;:&lt;/strong&gt; This post contains some outdated instructions. Please read &lt;a href="http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition"&gt; Installing Ruby on Rails and PostgreSQL on &lt;span class="caps"&gt;&lt;span class="caps"&gt;OS X&lt;/span&gt;&lt;/span&gt;, Third Edition&lt;/a&gt;, which is focused on Installing Ruby on Rails on Leopard.
&lt;/div&gt;
&lt;h2&gt;Step Zero: Install iTerm (optional)&lt;/h2&gt;


	&lt;p&gt;You&amp;#8217;ll spend a lot of time in your terminal as a Rails developer. I&amp;#8217;m not a big fan of Terminal.app as it lacks tabbed windows&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; and you&amp;#8217;ll often find me with around ten tabs open. I&amp;#8217;ve been using &lt;a href="http://iterm.sourceforge.net/"&gt;iTerm&lt;/a&gt; for a few years and it&amp;#8217;s definitely improved in the past year and doesn&amp;#8217;t seem to crash nearly as often as it used to.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://iterm.sourceforge.net/download.shtml"&gt;Download the latest iTerm release&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Once installed, I always change the default color scheme as I prefer the white on black schema. The menus in iTerm are lacking some thoughtful interaction design, but I&amp;#8217;ve figured out the right way to do it (after a long time of stumbling on it by accident). In iTerm, you&amp;#8217;ll want to &lt;strong&gt;edit&lt;/strong&gt; the Default bookmark, which you can access by going to Manage Bookmarks under the Bookmarks Menu.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://www.robbyonrails.com/files/ror_osx_iterm_bookmark.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Set the &lt;strong&gt;Display&lt;/strong&gt; value to &lt;strong&gt;classic iTerm&lt;/strong&gt; and you&amp;#8217;re golden.&lt;/p&gt;


	&lt;p&gt;Now&amp;#8230; let&amp;#8217;s get to business&amp;#8230;&lt;/p&gt;


	&lt;h2&gt;Step 1: Install Xcode Tools&lt;/h2&gt;


	&lt;p&gt;Without installing Xcode tools from Apple, we&amp;#8217;re not going to get very far. First, you&amp;#8217;ll need to grab a copy of Xcode, which you can download on Apple&amp;#8217;s Developer Connection site. It&amp;#8217;s almost a 1GB download, so you&amp;#8217;ll want to start your download and use your multi-tasking skills and &lt;a href="http://drinkviso.com/"&gt;grab a Viso&lt;/a&gt;, read some &lt;a href="http://www.planetrubyonrails.org"&gt;blog&lt;/a&gt; &lt;a href="http://therailsway.com/"&gt;posts&lt;/a&gt;.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://developer.apple.com/tools/download/"&gt;Download Xcode&lt;/a&gt; (dmg)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I&amp;#8217;m going to make the assumption here that you know how to install a dmg on osx. Once this is installed, you can move on to the next step!&lt;/p&gt;


	&lt;h2&gt;Step 2: All Your MacPorts are Belong to Us&lt;/h2&gt;


	&lt;p&gt;&lt;a href="http://www.macports.org/"&gt;MacPorts&lt;/a&gt; (formerly known as DarwinPorts) is a package management system for &lt;span class="caps"&gt;OS X&lt;/span&gt;. This is what we&amp;#8217;ll use to install most of the necessary programs to develop and run your Ruby on Rails applications. If you&amp;#8217;re from the Linux or &lt;span class="caps"&gt;BSD&lt;/span&gt; world, you are likely familiar with similar tools&amp;#8230; such as: &lt;code&gt;apt-get&lt;/code&gt;, &lt;code&gt;port&lt;/code&gt;, and &lt;code&gt;yum&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;You&amp;#8217;ll want to download MacPorts and install the dmg file.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://www.robbyonrails.com/files/ror_osx_macports.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Now that this is installed, we should test it.&lt;/p&gt;


	&lt;p&gt;With a new terminal, run the following:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ port version
Version: 1.442
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Success! Let&amp;#8217;s get going&amp;#8230;&lt;/p&gt;


	&lt;h2&gt;Step 3: Installing the Ruby on Rails development stack&lt;/h2&gt;


	&lt;p&gt;We&amp;#8217;re going to go through a series of small steps, which may take some time depending on how fast your internet connection and computer is.&lt;/p&gt;


	&lt;h3&gt;Install Ruby and RubyGems&lt;/h3&gt;


	&lt;p&gt;In order to install Ruby, we&amp;#8217;re going to use MacPorts with the &lt;code&gt;port&lt;/code&gt; command, which is now available for installing various packages on our &lt;span class="caps"&gt;OS X&lt;/span&gt; machines.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo port install ruby rb-rubygems&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;It&amp;#8217;ll probably take a while to download and install Ruby and all of it&amp;#8217;s known dependencies. In the meantime, check out &lt;a href="http://lolcode.com/"&gt;some funny code&lt;/a&gt;. &lt;span class="caps"&gt;KTHXBYE&lt;/span&gt;!&lt;/p&gt;


	&lt;p&gt;Still waiting for it to install, perhaps you could do something like&amp;#8230; begin writing a comment on this post, writing your own blog post, &lt;a href="http://www.youtube.com/watch?v=sLD0SNCFtyA"&gt;watch a funny video&lt;/a&gt;, or &lt;a href="http://workingwithrails.com/recommendation/new/person/5408-robby-russell"&gt;recommend me&lt;/a&gt;. I walked to &lt;a href="http://www.backspace.bz/"&gt;Backspace&lt;/a&gt; with Gary to get an Americano&amp;#8230; and it&amp;#8217;s still not done. :-p&lt;/p&gt;


	&lt;p&gt;(minutes/hours/weeks later)&lt;/p&gt;


	&lt;p&gt;Okay&amp;#8230; I trust that it finished installing Ruby and RubyGems without any hiccups. Let&amp;#8217;s test them from our terminal to make sure.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s check the version&amp;#8230;&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, let&amp;#8217;s make sure that Ruby is working properly&amp;#8230;&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
$ irb
irb(main):001:0&amp;gt; x = 1     
=&amp;gt; 1
irb(main):002:0&amp;gt; puts "wee!!!" if x == 1
wee!!!
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, we&amp;#8217;re on a roll. Let&amp;#8217;s get the rest of the stack installed.&lt;/p&gt;


	&lt;h3&gt;Install Ruby on Rails&lt;/h3&gt;


	&lt;p&gt;We&amp;#8217;re going to install Ruby on Rails with the &lt;code&gt;gem&lt;/code&gt; command that installing RubyGems provided.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ sudo gem install -y rails
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This command should produce an output similar to the following.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
Successfully installed rails-1.2.3
Successfully installed rake-0.7.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3
Installing ri documentation for rake-0.7.3...
Installing ri documentation for activesupport-1.4.2...
Installing ri documentation for activerecord-1.15.3...
Installing ri documentation for actionpack-1.13.3...
Installing ri documentation for actionmailer-1.3.3...
Installing ri documentation for actionwebservice-1.2.3...
Installing RDoc documentation for rake-0.7.3...
Installing RDoc documentation for activesupport-1.4.2...
Installing RDoc documentation for activerecord-1.15.3...
Installing RDoc documentation for actionpack-1.13.3...
Installing RDoc documentation for actionmailer-1.3.3...
Installing RDoc documentation for actionwebservice-1.2.3...    
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Install Rails-friendly gems&lt;/h3&gt;


	&lt;p&gt;&lt;strong&gt;Mongrel&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re developing with Rails, it&amp;#8217;s highly recommended that you use install and use &lt;a href="http://mongrel.rubyforge.org"&gt;Mongrel&lt;/a&gt; for your development and production environments. The following command will install the mongrel and mongrel_cluster gems (including their dependencies).&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo gem install -y mongrel mongrel_cluster&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;small&gt;* Note: Be sure to select the proper platform for mongrel. (hint: &lt;span class="caps"&gt;OS X&lt;/span&gt; is &lt;span class="caps"&gt;NOT&lt;/span&gt; mswin32)&lt;/small&gt;&lt;/p&gt;


	&lt;p&gt;My terminal output:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ sudo gem install -y mongrel mongrel_cluster
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Select which gem to install for your platform (i686-darwin8.9.1)
 1. mongrel 1.0.1 (mswin32)
 2. mongrel 1.0.1 (ruby)
 3. mongrel 1.0 (mswin32)
 4. mongrel 1.0 (ruby)
 5. Skip this gem
 6. Cancel installation
&amp;gt; 2
Select which gem to install for your platform (i686-darwin8.9.1)
 1. fastthread 1.0 (ruby)
 2. fastthread 1.0 (mswin32)
 3. fastthread 0.6.4.1 (mswin32)
 4. fastthread 0.6.4.1 (ruby)
 5. Skip this gem
 6. Cancel installation
&amp;gt; 1
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed mongrel-1.0.1
Successfully installed daemons-1.0.6
Successfully installed fastthread-1.0
Successfully installed gem_plugin-0.2.2
Successfully installed cgi_multipart_eof_fix-2.1
Installing ri documentation for mongrel-1.0.1...
Installing ri documentation for daemons-1.0.6...
Installing ri documentation for gem_plugin-0.2.2...
Installing ri documentation for cgi_multipart_eof_fix-2.1...
Installing RDoc documentation for mongrel-1.0.1...
Installing RDoc documentation for daemons-1.0.6...
Installing RDoc documentation for gem_plugin-0.2.2...
Installing RDoc documentation for cgi_multipart_eof_fix-2.1...
Successfully installed mongrel_cluster-0.2.1    
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;Step 4: Installing the World&amp;#8217;s Most Advanced Database Server&amp;#8230; PostgreSQL!&lt;/h2&gt;


	&lt;p&gt;At &lt;a href="http://planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt;, we develop our applications on top of &lt;a href="http://postgresql.or"&gt;PostgreSQL&lt;/a&gt;. I&amp;#8217;ve long been advocating the adoption of this &lt;em&gt;awesome&lt;/em&gt; open source database in the Rails community. Just over a year ago, &lt;a href="http://jvoorhis.com"&gt;Jeremy Voorhis&lt;/a&gt; (PLANET &lt;span class="caps"&gt;ARGON&lt;/span&gt; alumnus) and I were &lt;a href="http://odeo.com/audio/1069086/view"&gt;interviewed on the Ruby on Rails podcast&lt;/a&gt; and had the opportunity to discuss our preference of PostgreSQL over the alternatives (mysql, sqlite, firebird, etc.).&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;re going to install &lt;a href="http://www.postgresql.org/docs/8.2/static/release-8-2.html"&gt;PostgreSQL 8.2&lt;/a&gt; from MacPorts by running the following command.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo port install postgresql82 postgresql82-server&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;While this is installing, you might take a moment to check out &lt;a href="http://whytheluckystiff.net/comics/differentSpaceShuttles.html"&gt;some space shuttles&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Setting up PostgreSQL&lt;/h3&gt;


	&lt;p&gt;You may have noticed the output of the previous port installation of PostgreSQL 8.2, suggested that you do the following. Let&amp;#8217;s do that now&amp;#8230;&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ sudo mkdir -p /opt/local/var/db/postgresql82/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql82/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'    
&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Have PostgreSQL start automatically on system start-ups&lt;/h4&gt;


	&lt;p&gt;Unless you&amp;#8217;re concerned about extra applications running in the background, I&amp;#8217;d encourage you to add PostgreSQL to launchd, which will start it automatically after system reboots.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql82-server.plist&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Adding PostgreSQL commands to your $PATH&lt;/h4&gt;


	&lt;p&gt;For some reason, MacPorts doesn&amp;#8217;t add the PostgreSQL programs to the default bash &lt;span class="caps"&gt;PATH&lt;/span&gt;, which means that you can&amp;#8217;t run &lt;code&gt;psql&lt;/code&gt;, &lt;code&gt;pg_dump&lt;/code&gt;, or &lt;code&gt;createdb&lt;/code&gt;/&lt;code&gt;dropdb&lt;/code&gt; without specifying the full path to where they were installed. What we&amp;#8217;ll do is add them to our default terminal profile.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;sudo vi /etc/profile&lt;/code&gt;&lt;/pre&gt; (you can use &lt;code&gt;mate&lt;/code&gt;, &lt;code&gt;emacs&lt;/code&gt;, &lt;code&gt;joe&lt;/code&gt; or any other preferred editor to do this)

	&lt;p&gt;This file gets loaded every time a new terminal session is started.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s add &lt;code&gt;/opt/local/lib/postgresql82/bin&lt;/code&gt; to the end of the value for &lt;span class="caps"&gt;PATH&lt;/span&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/lib/postgresql82/bin"    
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Save the file and then open a new terminal. To test this, you should get the following output when you run &lt;code&gt;which psql&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ which psql
/opt/local/lib/postgresql82/bin/psql
&lt;/code&gt;&lt;/pre&gt;

	&lt;h4&gt;Creating a new PostgreSQL user&lt;/h4&gt;


	&lt;p&gt;When I&amp;#8217;m working on Rails applications in my development environment, I really don&amp;#8217;t want to have to specify a username and password in every &lt;code&gt;config/database.yml&lt;/code&gt; file for each of our ongoing client projects. When PostgreSQL was installed, it created a superuser named &lt;code&gt;postgres&lt;/code&gt;, which is great, but I&amp;#8217;d like one that matches my system username, so that I&amp;#8217;m not prompted at all for a username or password to connect to PostgreSQL.&lt;/p&gt;


	&lt;p&gt;To do this, we&amp;#8217;ll use the &lt;code&gt;createuser&lt;/code&gt; command, which comes with PostgreSQL. As you can see, I&amp;#8217;m creating a new user with superuser privileges (and will hopefully be the last time I have to do a -U postgres).&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ createuser --superuser robbyrussell -U postgres
CREATE ROLE
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Let&amp;#8217;s take a quick moment to test this out.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# create a new database
$ createdb my_test_db
CREATE DATABASE

# drop the database
$ dropdb my_test_db
DROP DATABASE
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, everything looks good here.&lt;/p&gt;


	&lt;p&gt;We now have a running installation of PostgreSQL with a new user account. All we need to do now is install the appropriate RubyGem to allow our Ruby applications to connect to it.&lt;/p&gt;


	&lt;h3&gt;Installing the Ruby Postgres gem&lt;/h3&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;: Hydro posted a commented, which lead me to the ruby-postgres gem.&lt;/p&gt;


	&lt;p&gt;You can install ruby-postgres gem by running the following command.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ sudo gem install -y ruby-postgres
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Let&amp;#8217;s take a moment to test that this installed properly.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
$ irb
irb(main):001:0&amp;gt; require 'rubygems'
=&amp;gt; true
irb(main):002:0&amp;gt; require 'postgres'
=&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;If this returns true, than we should be good to go. We&amp;#8217;ve now built a professional development environment for working with Ruby on Rails. &lt;strong&gt;Doesn&amp;#8217;t that feel great?&lt;/strong&gt;&lt;/p&gt;


	&lt;h2&gt;Test your install&lt;/h2&gt;


	&lt;p&gt;You can look back at &lt;a href="http://www.robbyonrails.com/articles/2006/05/29/install-ruby-rails-and-postgresql-on-osx"&gt;my older post&lt;/a&gt; to walk through the process of testing out your setup with a new Rails application.&lt;/p&gt;


	&lt;h2&gt;Closing thoughts&lt;/h2&gt;


	&lt;p&gt;I hope that this post has been useful for you. It took me a few hours to walk through this process and it&amp;#8217;s how all of our designers and developers at &lt;a href="http://planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; installs and configures their development environment.&lt;/p&gt;


	&lt;p&gt;We also install the following programs on new machines.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://macromates.com/"&gt;TextMate&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Subversion: &lt;code&gt;sudo port install subversion&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;RSpec: &lt;code&gt;sudo gem install -y rspec&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;...amongst other gems that are needed on specific projects&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Until next time&amp;#8230; have fun!&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Rumor: Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; Leopard will give Terminal.app tabs! (&lt;a href="http://www.apple.com/macosx/leopard/technology/unix.html"&gt;see screenshot&lt;/a&gt;)&lt;/p&gt;</description>
      <pubDate>Tue, 19 Jun 2007 13:54:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:99f3a321-f222-4716-b70e-f62fcb7829c1</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/06/19/installing-ruby-on-rails-and-postgresql-on-os-x-second-edition</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>PLANET ARGON</category>
      <category>rails</category>
      <category>ruby</category>
      <category>postgresql</category>
      <category>subversion</category>
      <category>irb</category>
      <category>rubyonrails</category>
      <category>osx</category>
      <category>tutorial</category>
      <category>apple</category>
      <category>rubygems</category>
      <category>xcode</category>
      <category>macports</category>
      <category>macbook</category>
    </item>
    <item>
      <title>Install Ruby, Rails, and PostgreSQL on OSX</title>
      <description>&lt;div class="warning"&gt;
&lt;strong&gt;&lt;span class="caps"&gt;WARNING&lt;/span&gt;:&lt;/strong&gt; This post contains some outdated instructions. Please read &lt;a href="http://www.robbyonrails.com/articles/2007/06/19/installing-ruby-on-rails-and-postgresql-on-os-x-second-edition"&gt; Installing Ruby on Rails and PostgreSQL on &lt;span class="caps"&gt;OS X&lt;/span&gt;, Second Edition&lt;/a&gt;.
&lt;/div&gt;

	&lt;p&gt;Our Creative Director, Allison Beckwith, picked up a new black MacBook this weekend and I had the luxury of getting it setup to model our standard setup. We all try to keep our setups fairly similar so that we don&amp;#8217;t hit too many issues when working together on projects.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ll try to keep this short and to the point&amp;#8230; because if you&amp;#8217;re like me&amp;#8230; you just want to start playing with Rails! ;-)&lt;/p&gt;


	&lt;p&gt;The steps I followed to get her setup like the rest of the development team at &lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; went something like this.&lt;/p&gt;


	&lt;h3&gt;XCode and DarwinPorts&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Download and install &lt;a href="http://iterm.sf.net/"&gt;iterm&lt;/a&gt; (the Universal dmg)&lt;/li&gt;
		&lt;li&gt;Download and install XCode tools from Apple (dmg)&lt;/li&gt;
		&lt;li&gt;Download and install &lt;a href="http://darwinports.opendarwin.org/"&gt;DarwinPorts&lt;/a&gt; (dmg)&lt;/li&gt;
		&lt;li&gt;Start up iterm.&lt;/li&gt;
	&lt;/ul&gt;


In this step we are going to modify the default bash profile so that every user on the machine that uses bash will get the path for darwinports in their bash_profile.
&lt;pre&gt;&lt;code&gt;sudo vi /etc/profile&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Modify the following line to include &lt;code&gt;/opt/local/bin&lt;/code&gt; in the &lt;span class="caps"&gt;PATH&lt;/span&gt;&amp;#8230; save the file (see vim documentation for details)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  PATH="/bin:/sbin:/opt/local/bin:/usr/bin:/usr/sbin" 
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Ruby and Rails&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Open up a new iterm tab (apple-t)&lt;/li&gt;
		&lt;li&gt;Install ruby with darwinports with: &lt;code&gt;sudo port install ruby rb-rubygems&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Install Ruby on Rails and all its dependencies with: &lt;code&gt;sudo gem install -y rails&lt;/code&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;h3&gt;PostgreSQL and Ruby libs&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Install PostgreSQL8 with: &lt;code&gt;sudo port install postgresql8&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;We need to modify the &lt;code&gt;/etc/profile&lt;/code&gt; file again because the postgresql8 install doesn&amp;#8217;t add programs like pg_ctl to /opt/local/bin. Change the &lt;span class="caps"&gt;PATH&lt;/span&gt; to now look like this and save.&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
  PATH="/bin:/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/lib/pgsql8/bin" 
&lt;/code&gt;&lt;/pre&gt;

	&lt;ul&gt;
	&lt;li&gt;Install the &lt;strong&gt;postgres&lt;/strong&gt; gem with: &lt;code&gt;sudo gem install postgres&lt;/code&gt;
	&lt;ul&gt;
	&lt;li&gt;Oh NO!!! You should see an error about it not finding libraries&amp;#8230; what will we do?&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
  cd /opt/local/lib/ruby/gems/1.8/gems/postgres-0.7.1
  sudo ruby extconf.rb --with-pgsql-include=/opt/local/include/pgsql8 --with-pgsql-lib=/opt/local/lib/pgsql8
  sudo make &amp;#38;&amp;#38; sudo make install
  # for good measure...
  sudo gem install postgres
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;strong&gt;Successfully installed postgres-0.7.1&lt;/strong&gt;&lt;/p&gt;


	&lt;h3&gt;Configure PostgreSQL for single user&lt;/h3&gt;


	&lt;p&gt;In our development environments, we don&amp;#8217;t find it necessary to keep PostgreSQL running all the time on our servers. We only want it running when we&amp;#8217;re doing development. We also typically install it per user on a machine to keep us from needing things like usernames and passwords to connect to it from an application we&amp;#8217;re running on the machine. Let&amp;#8217;s setup PostgreSQL the &lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt; way!&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Open up iterm and go to your home directory&lt;/li&gt;
		&lt;li&gt;Init your new PostgreSQL database with: &lt;code&gt;initdb -D pgdata&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Start up PostgreSQL with: &lt;code&gt;pg_ctl -D pgdata -l pgdata/psql.log start&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Create a new database with: &lt;code&gt;createdb argon_development&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Test the new database with: &lt;code&gt;psql argon_development&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Did it load up your new database? If so, great! If not&amp;#8230; check your steps&amp;#8230; :-)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Test Rails + PostgreSQL&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Navigate to a directory where you don&amp;#8217;t mind sticking projects&amp;#8230; &lt;code&gt;mkdir development; cd development&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Generate a new Rails application with: &lt;code&gt;rails -d postgresql argon&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Navigate to new Rails application directory. &lt;code&gt;cd argon&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Generate a new model to test with: &lt;code&gt;./script/generate model Argonista&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Edit and save the migration that was generated ( &lt;code&gt;db/migrate/001_create_argonistas.rb&lt;/code&gt; ) file with your favorite editor&amp;#8230;&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
  class CreateArgonistas &amp;lt; ActiveRecord::Migration
    def self.up
      create_table :argonistas do |t|
        t.column :name, :string
        t.column :blog_url, :string
      end
    end

    def self.down
      drop_table :argonistas
    end
  end
&lt;/code&gt;&lt;/pre&gt;

	&lt;ul&gt;
	&lt;li&gt;Edit &lt;code&gt;config/database.yml&lt;/code&gt; to look like the following&amp;#8230; you&amp;#8217;ll notice that we don&amp;#8217;t need to supply a username or password.&lt;/li&gt;
	&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
  development:
    adapter: postgresql
    database: argon_development

  test:
    adapter: postgresql 
    database: argon_test

  production:
    adapter: postgresql
    database: argon_production
&lt;/code&gt;&lt;/pre&gt;

* Run the migration with: &lt;code&gt;rake db:migrate&lt;/code&gt;
&lt;pre&gt;&lt;code&gt;
  $ rake db:migrate
  (in /Users/allisonbeckwith/development/argon)
  == CreateArgonistas: migrating ================================================
  -- create_table(:argonistas)
  NOTICE:  CREATE TABLE will create implicit sequence "argonistas_id_seq" for serial column "argonistas.id" 
  NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "argonistas_pkey" for table "argonistas" 
     -&amp;gt; 0.0399s
  == CreateArgonistas: migrated (0.0402s) =======================================
&lt;/code&gt;&lt;/pre&gt;

* Test your new model from console
&lt;pre&gt;&lt;code&gt;
  $ ./script/console 
  Loading development environment.
  &amp;gt;&amp;gt; a = Argonista.new
  =&amp;gt; #&amp;lt;Argonista:0x24569dc @attributes={"name"=&amp;gt;nil, "blog_url"=&amp;gt;nil}, @new_record=true&amp;gt;
  &amp;gt;&amp;gt; a.name = 'Robby'
  =&amp;gt; "Robby" 
  &amp;gt;&amp;gt; a.blog_url = 'http://www.robbyonrails.com'
  =&amp;gt; "http://www.robbyonrails.com" 
  &amp;gt;&amp;gt; a.save
  =&amp;gt; true
  &amp;gt;&amp;gt; exit
&lt;/code&gt;&lt;/pre&gt;

* Great, let&amp;#8217;s go look at our database table&amp;#8230;
&lt;pre&gt;&lt;code&gt;
  $ psql argon_development
  Welcome to psql 8.1.3, the PostgreSQL interactive terminal.

  Type:  \copyright for distribution terms
         \h for help with SQL commands
         \? for help with psql commands
         \g or terminate with semicolon to execute query
         \q to quit

  argon_development=# SELECT * FROM argonistas;
   id | name  |          blog_url           
  ----+-------+-----------------------------
    1 | Robby | http://www.robbyonrails.com
  (1 row)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;There we go, we&amp;#8217;ve setup Ruby, Rails, and PostgreSQL on a brand new Intel MacBook without breaking a sweat!&lt;/p&gt;


	&lt;h3&gt;Extra Goodies&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Subversion: &lt;code&gt;sudo port install subversion&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Lighttpd: &lt;code&gt;sudo port install lighttpd&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;ImageMagick: &lt;code&gt;sudo port install ImageMagick&lt;/code&gt; (known to take a while&amp;#8230;)&lt;/li&gt;
		&lt;li&gt;GraphicsMagick: &lt;code&gt;sudo port install GraphicsMagick&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Install the rmagick gem: &lt;code&gt;sudo gem install rmagick&lt;/code&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Have fun!&lt;/p&gt;</description>
      <pubDate>Mon, 29 May 2006 09:46:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:6faf4e72-89d7-433c-8e6a-059509001562</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2006/05/29/install-ruby-rails-and-postgresql-on-osx</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>PLANET ARGON</category>
      <category>osx</category>
      <category>tutorial</category>
      <category>postgresql</category>
      <category>rubyonrails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>PostgreSQL: An elephant wearing a hula skirt and I find it sexy</title>
      <description>&lt;p&gt;Last week, I gave a &lt;a href="http://www.robbyonrails.com/articles/2006/04/14/sneaking-rails-through-the-legacy-system"&gt;live presentation&lt;/a&gt; to ~250 people, which was basically me walking through the process of using &lt;a href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt; to talk to a &lt;em&gt;legacy&lt;/em&gt; database&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;. For my example, I used the &lt;a href="http://pgfoundry.org/projects/dbsamples"&gt;Dell &lt;span class="caps"&gt;DVD&lt;/span&gt; database&lt;/a&gt;... the PostgreSQL version. You can review some comments about my presentation by reviewing &lt;a href="http://blog.zenspider.com/archives/2006/04/canadaonrails_d_1.html"&gt;this entry&lt;/a&gt; on the blog of Ryan Davis. I wrapped quite a bit of the database in a few minutes and then showed what another 45 minutes of work could do with Rails. I&amp;#8217;ll tarball that code and post it online soon.&lt;/p&gt;


	&lt;p&gt;Alex Bunardzic &lt;a href="http://jooto.com/blog/index.php/2006/04/19/practical-aspects-of-canada-on-rails/"&gt;found it practical&lt;/a&gt;. I&amp;#8217;ll take that as a compliment. ;-)&lt;/p&gt;


	&lt;p&gt;Earlier, I noticed &lt;a href="http://cwilliams.textdriven.com:8002/articles/2006/04/20/ruby-rails-and-web-development-drving-significant-book-sales"&gt;this blog entry&lt;/a&gt; by Chris&amp;#8230; where he said, &amp;#8220;PostgreSQL also seems to be growing more briskly among the database category, while MySQL declines modestly. I guess that&amp;#8217;s good news for Robby.&amp;#8221; What exactly made me happy? This bullet made by Tim O&amp;#8217;Reilly on Radar in his post, &lt;a href="http://radar.oreilly.com/archives/2006/04/state_of_the_computer_book_mar_3.html"&gt;State of the Computer Book Market, Part 2&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&amp;#8220;A surprise to many may be the s&lt;strong&gt;trong growth of &lt;a href="http://www.postgresql.orgf"&gt;PostgreSQL&lt;/a&gt;, up 84% over a year ago&lt;/strong&gt;. We&amp;#8217;ve also been hearing some signs of growth in the Postgres market from our &amp;#8220;alpha geek&amp;#8221; radar, with reasons given including better support for geo data, and better handling of very large data sets. New companies like Greenplum and EnterpriseDB have also brought a little focus to this market. We&amp;#8217;re updating our &lt;strong&gt;PostgreSQL&lt;/strong&gt; book, and watching this market closely.&amp;#8221;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s awesome! Go PostgreSQL!&lt;/p&gt;


	&lt;p&gt;Then to my surprise, I was contacted by &lt;span class="caps"&gt;CRN&lt;/span&gt; (again) to get my thoughts on &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/blackhole-storage-engine.html"&gt;MySQL&amp;#8217;s awesome &lt;em&gt;storage-engine plugin&lt;/em&gt; system&lt;/a&gt;... which showed up a few hours later in &lt;a href="http://crn.com/sections/breakingnews/breakingnews.jhtml?articleId=186500172"&gt;this article&lt;/a&gt;. The writer of that article managed to goof my last name (Robby Hill?)... and hopefully that gets resolved soon. ;-)&lt;/p&gt;


	&lt;p&gt;As I said at &lt;a href="http://www.canadaonrails.org"&gt;Canada on Rails&lt;/a&gt; in front of 250 people, &amp;#8220;I find databases&amp;#8230; sexy.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.planetargon.com/files/~robby/pg_pink_elephant.jpg"&gt;&lt;img src="http://www.planetargon.com/files/~robby/pg_pink_elephant-thumb.jpg" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;(free desktop wallpaper!)&lt;/p&gt;


	&lt;p&gt;Why Rails? Why PostgreSQL?&lt;/p&gt;


	&lt;p&gt;Rails.. that&amp;#8217;s a no-brainer.&lt;/p&gt;


	&lt;p&gt;PostgreSQL? Well.. they have compatible licenses&amp;#8230; no dual-license smell when your trying to sell your application as a complete solution&amp;#8230; and as &lt;a href="http://www.robbyonrails.com/articles/2005/09/27/the-bitter-sweet-taste-of-agnostic-database-schemas"&gt;Rails is database agnostic&lt;/a&gt;... there is no reason not to give PostgreSQL a try.&lt;/p&gt;


	&lt;p&gt;Who uses PostgreSQL on Rails?&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.cdbaby.com"&gt;CDBaby&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.shopify.com"&gt;Shopify&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; (on almost every project we work on&amp;#8230;)&lt;/li&gt;
		&lt;li&gt;you&amp;#8230;?&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;If your using PostgreSQL on Rails&amp;#8230; &lt;a href="mailto:robby@planetargon.com"&gt;email me&lt;/a&gt;... I&amp;#8217;d love to hear and share your story on my O&amp;#8217;Reilly blog, like I did with Derek Sivers and Jeremy Kemper of &lt;a href="http://www.cdbaby.com"&gt;CDBaby&lt;/a&gt; a few months ago, which you can &lt;a href="http://www.oreillynet.com/pub/wlg/8274"&gt;read here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;again&amp;#8230; &lt;a href="http://noodlejunkie.com/?p=23"&gt;I find databases sexy&lt;/a&gt;...&lt;/p&gt;


	&lt;p&gt;If your a &lt;strong&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/strong&gt; hosting customer&amp;#8230; you can follow &lt;a href="http://docs.planetargon.com/wiki/show/Setup+A+PostgreSQL+Database"&gt;these instructions&lt;/a&gt; to install PostgreSQL on your &lt;a href="http://www.planetargon.com/hosting.html"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt; hosting&lt;/a&gt; account.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; According to the Rails convention (and by me)... any database created pre-Rails or doesn&amp;#8217;t follow the conventions is considered legacy. ;-)&lt;/p&gt;
</description>
      <pubDate>Thu, 20 Apr 2006 18:30:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:363a8c6f-7b8c-462e-b91f-fb9b5d5e5c50</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2006/04/20/postgresql-an-elephant-wearing-a-hula-skirt-and-i-find-it-sexy</link>
      <category>postgresql</category>
      <category>programming</category>
      <category>databases</category>
    </item>
    <item>
      <title>I Repeat... Do Not Use PostgreSQL!</title>
      <description>&lt;p&gt;Why is everybody interested in using &lt;a href="http://postgresql.org"&gt;PostgreSQL&lt;/a&gt;? We all know that it&amp;#8217;s a pain to install, a pain to maintain, and Rails only works with MySQL. So, why do we bother?&lt;/p&gt;


	&lt;p&gt;This article titled, &lt;a href="http://searchopensource.techtarget.com/originalContent/0,289142,sid39_gci1172668,00.html"&gt;Five reasons why you should never use PostgreSQL. Ever.&lt;/a&gt; clears up these questions.&lt;/p&gt;


	&lt;p&gt;My favorite is&amp;#8230; &lt;em&gt;&amp;#8220;Reason #5: You (don&amp;#8217;t) get what you (don&amp;#8217;t) pay for&amp;#8221;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Imagine if we said the same thing about &lt;a href="http://www.rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;?&lt;/p&gt;


	&lt;p&gt;&lt;small&gt;
Similar Post(s): &lt;a href="http://robbyonrails.com/articles/2005/09/27/the-bitter-sweet-taste-of-agnostic-database-schemas"&gt;The bitter-sweet taste of agnostic database schemas&lt;/a&gt;,  &lt;a href="http://robbyonrails.com/articles/2005/11/30/localization-with-rails-and-postgresql-part-1"&gt;Localization with Rails and PostgreSQL, part 1&lt;/a&gt;
&lt;/small&gt;&lt;/p&gt;
</description>
      <pubDate>Tue, 14 Mar 2006 09:16:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:a4e02c8e-a4a9-4b22-8189-10da420e0cfc</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2006/03/14/i-repeat-do-not-use-postgresql</link>
      <category>postgresql</category>
      <category>programming</category>
      <category>rails</category>
      <category>sarcasm</category>
    </item>
    <item>
      <title>Localization with Rails and PostgreSQL, part 1</title>
      <description>&lt;p&gt;One of the client projects that &lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; is working on requires that it work in about &lt;strong&gt;20 different languages&lt;/strong&gt;. &lt;a href="http://jvoorhis.com"&gt;Jeremy&lt;/a&gt; has been investigating different plugins for Rails to help us accomplish this. He came across &lt;a href="http://globalize.diluvia.net/wiki"&gt;Globalize&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&lt;a href="http://globalize.diluvia.net/wiki"&gt;Globalize&lt;/a&gt; is a Ruby on Rails plugin designed to support multilingual applications. It’s under the &lt;span class="caps"&gt;MIT&lt;/span&gt; License, same as Ruby on Rails.&lt;/em&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;Locale&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;set&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;en-US&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="ident"&gt;d&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Diet&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="number"&gt;1&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt; 
&lt;span class="ident"&gt;d&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;name&lt;/span&gt; &lt;span class="punct"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Vegetarian&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;... we want to pull back the German version. No, it doesn&amp;#8217;t translate it for you.. just pulls back another version of the object with the desired locale.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;Locale&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;set&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;de-DE&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="ident"&gt;d&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Diet&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="number"&gt;1&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt; 
&lt;span class="ident"&gt;d&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;name&lt;/span&gt; &lt;span class="punct"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Vegetarier&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Pretty cool, right?&lt;/p&gt;


	&lt;p&gt;Well, we&amp;#8217;re primarily working with &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt; and the Globalize plugin didn&amp;#8217;t pass tests with it. That&amp;#8217;s now fixed as I  found out from &lt;a href="http://jvoorhis.com"&gt;Jeremy&lt;/a&gt; that he was given &lt;span class="caps"&gt;COMMIT&lt;/span&gt; rights to the Globalize plugin and it now passes all tests against PostgreSQL!&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;ll keep you updated on how well it works as we dig deeper into using it. :-)&lt;/p&gt;
</description>
      <pubDate>Wed, 30 Nov 2005 12:36:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:0058dd2b277ba20106569bc6f2ce2220</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/11/30/localization-with-rails-and-postgresql-part-1</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>rubyonrails</category>
      <category>postgresql</category>
      <category>planetargon</category>
      <category>localization</category>
    </item>
    <item>
      <title>Interviewed by CRN regarding Oracle, MySQL, and PostgreSQL</title>
      <description>&lt;p&gt;I was interviewed by &lt;span class="caps"&gt;CRN&lt;/span&gt; regarding my personal thoughts on how the release of Oracle Express might compete with MySQL and &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.crn.com/sections/software/software.jhtml?articleId=173403216"&gt;Read the short article&amp;#8230;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Oracle Express&amp;#8230; &lt;strong&gt;{yawn}&lt;/strong&gt;&lt;/p&gt;
</description>
      <pubDate>Sat, 12 Nov 2005 21:49:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:ecb4ed773f2bb0c870d62a4c0178dd1a</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/11/12/interviewed-by-crn-regarding-oracle-mysql-and-postgresql</link>
      <category>Off-Topic</category>
      <category>PostgreSQL</category>
      <category>postgresql</category>
      <category>oracle</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Rails Migrations and PostgreSQL Constraints</title>
      <description>&lt;p&gt;A question was posed on the Rails mailing list concerning how one would go about adding CONSTRAINTs to the database tables with &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html"&gt;ActiveRecord::Migration&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;One argument was raised stating that it is easier to handle these in plain &lt;span class="caps"&gt;SQL&lt;/span&gt; schema files. I disagree. :-)&lt;/p&gt;


	&lt;h3&gt;Migrations to the Rescue&lt;/h3&gt;


	&lt;p&gt;Databases evolve and I have recently found the Migration structure to be perfect for handling iterations and schema changes. Using the &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#M000529"&gt;#execute&lt;/a&gt; method has helped move more of my code into the Ruby/Rails framework&amp;#8230; and that just makes things easier to manage in the long-run. This is the approach that we are using at &lt;a href="http://www.planetargon.com/development.html"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; with some of our current client projects.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="comment"&gt;# db/migrate/6_add_foreign_key.rb&lt;/span&gt;
&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;AddForeignKey&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Migration&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;self.up&lt;/span&gt;
    &lt;span class="ident"&gt;execute&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;ALTER TABLE bees ADD CONSTRAINT beehive_id_fkey FOREIGN KEY
(beehive_id) REFERENCES beehives (id);&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;self.down&lt;/span&gt;
    &lt;span class="ident"&gt;execute&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;ALTER TABLE bees DROP CONSTRAINT beehive_id_fkey;&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This gives us an easy way to use the standard, &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M000507"&gt;#create_table&lt;/a&gt; syntax for building our tables with Ruby&amp;#8230; and then we can slap these constraints on later.&lt;/p&gt;


	&lt;p&gt;This would add the constraints&amp;#8230;&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;
rake migrate VERSION=6
&lt;/pre&gt;
&lt;/code&gt;

...run tests&amp;#8230;
&lt;code&gt;
&lt;pre&gt;
rake
&lt;/pre&gt;
&lt;/code&gt;

...roll back&amp;#8230;
&lt;code&gt;
&lt;pre&gt;
rake migrate VERSION=5
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;I have found that this approach is really useful with testing in Rails. When I think that I have everything working great (without &lt;span class="caps"&gt;CONSTRAINTS&lt;/span&gt; in PostgreSQL), I run another migration to add a bunch of foreign key and data constraints to the tables and&amp;#8230; run my tests again.&lt;/p&gt;


	&lt;h3&gt;Let&amp;#8217;s give Active Record a Hug&lt;/h3&gt;


	&lt;p&gt;This has helped me &lt;a href="http://www.robbyonrails.com/articles/2005/09/27/the-bitter-sweet-taste-of-agnostic-database-schemas"&gt;gain some trust&lt;/a&gt; in Active Record while still giving me that comforting feeling that &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt; is acting as the &lt;em&gt;body guard for my data&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;Even if you don&amp;#8217;t end up using Migrations to handle these types of database schema changes, I would highly suggest that you model your implementation after this. I&amp;#8217;ve worked with many database schemas and this just makes it easy to add your new change and run one command to commit it to the database.&lt;/p&gt;


	&lt;p&gt;...and now I go play with beehives&amp;#8230;&lt;/p&gt;
</description>
      <pubDate>Fri, 11 Nov 2005 10:42:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f125682d520f030e69dadb4be8913ebe</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/11/11/rails-migrations-and-postgresql-constraints</link>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>rails</category>
      <category>postgresql</category>
      <category>migrations</category>
      <category>database</category>
      <category>activerecord</category>
    </item>
    <item>
      <title>PostgreSQL 8.1 was released!</title>
      <description>&lt;p&gt;Just a quick announcemnet:&lt;/p&gt;


	&lt;p&gt;Yesterday, the PostgreSQL team &lt;a href="http://www.postgresql.org/about/news.422"&gt;released version 8.1&lt;/a&gt;. Take a peak at the &lt;a href="http://www.postgresql.org/docs/current/static/release.html#RELEASE-8-1"&gt;latest changes and enhancements&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Yes, we&amp;#8217;re offering &lt;a href="http://www.planetargon.com/postgresql_hosting.html"&gt;PostgreSQL 8.1 Hosting&lt;/a&gt; and &lt;a href="http://www.planetargon.com/support.html"&gt;Support&lt;/a&gt; for it now at &lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt;. :-)&lt;/p&gt;
</description>
      <pubDate>Wed, 09 Nov 2005 18:21:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e2791496d00313634489fbf3ea1a7b95</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/11/09/postgresql-8-1-was-released</link>
      <category>PostgreSQL</category>
      <category>postgresql</category>
      <category>hosting</category>
      <category>rails</category>
    </item>
    <item>
      <title>Interview with CD Baby</title>
      <description>&lt;p&gt;Last month I conducted an interview with Derek Sivers and Jeremy Kemper of CD Baby&amp;#8230; this is &lt;a href="http://www.oreillynet.com/pub/wlg/8274"&gt;the result&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Wed, 02 Nov 2005 16:25:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:6ef7e35fcabbdc78afa2890eb3bc7541</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/11/02/interview-with-cd-baby</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>rails</category>
      <category>cdbaby</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>Migrating from MySQL to PostgreSQL in 60 seconds (with Rails)</title>
      <description>&lt;p&gt;I do quite a few MySQL to PostgreSQL migrations for clients of &lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; and over the years I have gone through different methods of handling this procedure. Typically, it involved exporting data, re-importing it through some shell script that does its best to take into consideration the slight differences between the two databases.&lt;/p&gt;


	&lt;p&gt;While working on a recent project that was to be migrated from &lt;a href="http://sql-info.de/mysql/gotchas.html"&gt;MySQL&lt;/a&gt; to &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt;, but after some &lt;a href="http://www.refactoringrails.com"&gt;Refactoring&lt;/a&gt; had been done to the code base. I had been meaning to spend a few hours coming up with some simplified process of taking data from MySQL and replicating it to a new PostgreSQL database, while maintaining  referential integrity.&lt;/p&gt;


	&lt;p&gt;My original idea was to build a script that referenced two seperate databases and then copied data out and inserted it into the new db after performing a few data changes. This seemed like too much work and I knew that I should be able to harness the power of Ruby and Rails in my process. My next thought? &lt;a href="http://redhanded.hobix.com/inspect/railsfsAfterACoupleMinutesOfToolingWithFuseWhoa.html"&gt;RailsFS&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;In a &lt;strong&gt;perfect&lt;/strong&gt; world, I would mount one instance of the application with a mysql database and another with a postgresql database&amp;#8230; and just copy the yaml files to the postgresql and bam, it&amp;#8217;d work, right? Well, it doesn&amp;#8217;t quite work that way. So, I ruled out that idea.&lt;/p&gt;


	&lt;p&gt;Then I had another idea. I would build a task in my Rakefile that&amp;#8230; imported each of those &lt;span class="caps"&gt;YAML&lt;/span&gt; files into PostgreSQL!&lt;/p&gt;


	&lt;p&gt;We can now type in the following commands:&lt;/p&gt;


This first creates my PostgreSQL database tables using Migrations.
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;migrate&lt;/span&gt; &lt;span class="constant"&gt;VERSION&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;then&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;mysql2pgsql&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;code&gt;mysql2pgsql&lt;/code&gt; runs&amp;#8230;and approx 60 seconds later, I had an exact copy of the MySQL database in PostgreSQL. 

But wait! PostgreSQL has &lt;span class="caps"&gt;SEQUENCES&lt;/span&gt;&amp;#8230; so I then run:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;migrate&lt;/span&gt; &lt;span class="constant"&gt;VERSION&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;...and my &lt;span class="caps"&gt;SEQUENCES&lt;/span&gt; are &lt;span class="caps"&gt;ALTER&lt;/span&gt;&amp;#8217;d.&lt;/p&gt;


	&lt;p&gt;Yes, I will post some code in the near future. But all I am doing is basically running through all the &lt;span class="caps"&gt;YAML&lt;/span&gt; files that are available from RailsFS and adding them into the new database. It automatically figures out the model name&amp;#8230;and is fairly generic at the moment. However, I&amp;#8217;d like to spend a bit more time stress-testing it before I post it. :-)&lt;/p&gt;


	&lt;p&gt;I want to try to work on a RailsFS-less version as well so that I can run this on my PowerBook.&lt;/p&gt;


	&lt;p&gt;Until next time&amp;#8230; have fun!&lt;/p&gt;
</description>
      <pubDate>Sat, 29 Oct 2005 14:23:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b1064070f97315072ad3be65a29dc575</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/29/migrating-from-mysql-to-postgresql-in-60-seconds-with-rails</link>
      <category>Ruby on Rails</category>
      <category>PostgreSQL</category>
      <category>rails</category>
      <category>activerecord</category>
      <category>postgresql</category>
      <category>mysql</category>
      <category>fusefs</category>
    </item>
    <item>
      <title>Using Named Placeholders in Ruby</title>
      <description>&lt;p&gt;&lt;strong&gt;Insert Hip Quote Here:&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&amp;#8220;In ancient times, hundreds of years before the dawn of history, an ancient race of people&amp;#8230; the Druids. No one knows who they were or what they were doing&amp;#8230; &amp;#8220;&lt;/em&gt; &amp;#8211; Nigel Tufnel, Spinal Tap&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Story Time&amp;#8230;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Earlier, I was giving a customer of ours, Jared from &lt;a href="http://www.communitywalk.com"&gt;CommunityWalk.com&lt;/a&gt; a quick tutorial on some of the features script/console&amp;#8230; which lead to helping him with a &lt;span class="caps"&gt;SQL&lt;/span&gt; query. When I provided him with some working code he was curious about what I had done in the &lt;span class="caps"&gt;SQL&lt;/span&gt; query string that I was passing to &lt;code&gt;find_by_sql&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;WARNING&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;If you have &lt;span class="caps"&gt;ANY SQL&lt;/span&gt; queries that resembles the following, &lt;span class="caps"&gt;PLEASE READ THE REST OF THIS&lt;/span&gt;. :-)&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:search&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;first_name = '&lt;span class="expr"&gt;#{values['first_name']}&lt;/span&gt;'&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;If you are doing that&amp;#8230; then you are opening yourself up to some security problems. Let&amp;#8217;s take a few minutes and discuss how you can make this more secure and still keep your code readable. (the best of both worlds!)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;The ? Placeholder&lt;/strong&gt;&lt;/p&gt;


Many of you are probably familiar with this approach&amp;#8230;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;['&lt;/span&gt;&lt;span class="string"&gt;first_name = ?&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Nigel&lt;/span&gt;&lt;span class="punct"&gt;']&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;

&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;['&lt;/span&gt;&lt;span class="string"&gt;first_name = ? AND last_name = ?&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Nigel&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Tufnel&lt;/span&gt;&lt;span class="punct"&gt;']&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;You can pass it a hash as well.. and as long as you put everything in the same order as the &lt;code&gt;?&lt;/code&gt;s are placed&amp;#8230; then all is well.&lt;/p&gt;


	&lt;p&gt;My only real problem with this approach is that it requires you to keep things in a specific sequential order&amp;#8230; and who wants to keep track of that? So, I would like to recommend that you use named placeholders. Aside from that, it looks magical and I don&amp;#8217;t like magical-looking code. I like &lt;em&gt;easy to read code&lt;/em&gt;. :-)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Named Placeholders&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;If you already use these&amp;#8230; you know how  useful they can be in your &lt;span class="caps"&gt;SQL&lt;/span&gt; queries. If you haven&amp;#8217;t seen them before&amp;#8230; it&amp;#8217;s because the Rails docs don&amp;#8217;t really mention it and is something that comes from the underlying database library in Ruby. So what is so great about these?&lt;/p&gt;


Let&amp;#8217;s first replace the above code with named parameters&amp;#8230;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;['&lt;/span&gt;&lt;span class="string"&gt;first_name = :first_name&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="symbol"&gt;:first_name&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Nigel&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;We are passing a hash with a matching key to the conditions option. Pretty neat, right? In this case with just one placeholder we just increased the amount of code to do the same thing. So, it might always be the best solution&amp;#8230; but it is &lt;em&gt;easier to read&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s try another with multiple keys in our hash&amp;#8230; infact, we&amp;#8217;ll build the hash prior to calling &lt;code&gt;find&lt;/code&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="symbol"&gt;:first_name&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Nigel&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="symbol"&gt;:last_name&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Tufnel&lt;/span&gt;&lt;span class="punct"&gt;'}&lt;/span&gt;
&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;['&lt;/span&gt;&lt;span class="string"&gt;first_name = :first_name AND last_name = :last_name&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;It will happily match the hash keys to the named placeholders in the conditions string. Again, nothing terribly exciting&amp;#8230;but it is &lt;em&gt;easier to read&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Who cares about order? Not named placeholders!&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Okay, let&amp;#8217;s mix things up a bit&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="symbol"&gt;:last_name&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Tufnel&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="symbol"&gt;:first_name&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Nigel&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;
&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;['&lt;/span&gt;&lt;span class="string"&gt;first_name = :first_name AND last_name = :last_name&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The hash keys were not added in the same order&amp;#8230; but it still works!&lt;/p&gt;


	&lt;p&gt;Okay, now for one last quick example (it&amp;#8217;s late and I am tired&amp;#8230;).&lt;/p&gt;


	&lt;p&gt;I have a search mechanism on a site that allows you to search for a string of text across multiple fields. So, I have one string&amp;#8230; but several fields to compare against.&lt;/p&gt;


Here is a string that I will pass to the &lt;code&gt;find&lt;/code&gt; method.
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;conditions&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;role = :role AND (first_name ~* :str OR last_name ~* :str OR nick_name ~* :str)&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: this string is using &lt;a href="http://rubyurl.com/DYE"&gt;PostgreSQL regular expressions&lt;/a&gt;... (&lt;code&gt;~*&lt;/code&gt;).&lt;/p&gt;


	&lt;p&gt;Here is a hash that with that matches the keys, &lt;code&gt;:str&lt;/code&gt; and &lt;code&gt;:role&lt;/code&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="symbol"&gt;:str&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;^(Nigel|Tufnel)$&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="symbol"&gt;:role&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Guitar&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;If you look above, you&amp;#8217;ll see that the &lt;code&gt;conditions&lt;/code&gt; string contains &lt;strong&gt;four&lt;/strong&gt; named placeholders&amp;#8230; but the hash only has &lt;strong&gt;two&lt;/strong&gt; keys. With the &lt;code&gt;?&lt;/code&gt; placeholder, we would have to pass the same vaule three times&amp;#8230; which isn&amp;#8217;t any fun to read or maintain. ;-/&lt;/p&gt;


	&lt;p&gt;So, with our new friends, &lt;strong&gt;named parameters&lt;/strong&gt;, we can call &lt;code&gt;find&lt;/code&gt; (or any find-like method) using this technique for placeholders.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;RockLegend&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:conditions&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt; &lt;span class="ident"&gt;conditions&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;...and hopefully this is useful to you.  :-)&lt;/p&gt;


	&lt;p&gt;Have fun!&lt;/p&gt;
</description>
      <pubDate>Fri, 21 Oct 2005 00:53:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ffd337b75c41f3b73433e7919ddca5e</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/21/using-named-placeholders-in-ruby</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>activerecord</category>
      <category>rails</category>
      <category>ruby</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>New Active Record Options for Associations</title>
      <description>&lt;p&gt;Two months ago today I posted about a bug in Active Record. A bug that reminded me to remain cautious about how much trust I put into a database abstraction layer. I am happy to now say  that this particular bug has been fixed, and I got to help! In the process, I also got to add some new features. (see my original rant, &lt;a href="http://www.robbyonrails.com/articles/2005/08/18/active-record-i-3-u-but-i-still-trust-my-database-server-a-tiny-bit-more"&gt;Active Record, I love U but I still trust my database server a tiny bit more&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I discovered this bug when I was working on a chapter in &lt;a href="http://www.programmingrails.com"&gt;my book&lt;/a&gt; on Active Record. I&amp;#8217;m known to gladly take advantage of database constraints and triggers, and it was when I decided to test my code &lt;strong&gt;without&lt;/strong&gt; these constraints, I discovered the bug. &lt;em&gt;&amp;#8220;Hey, Active Record isn&amp;#8217;t doing what it&amp;#8217;s supposed to!&amp;#8221;&lt;/em&gt; I&amp;#8217;ve since had a number of people ask me if what a more pragmatic way to work around this issue is, rather than go my route by adding a constraint/trigger.&lt;/p&gt;


	&lt;p&gt;You can now &lt;strong&gt;&lt;span class="caps"&gt;DO AWAY&lt;/span&gt;&lt;/strong&gt; with &lt;strong&gt;&lt;code&gt;ON DELETE CASCADE&lt;/code&gt;!&lt;/strong&gt; (sort of)&lt;/p&gt;


	&lt;p&gt;The new release of Rails 1.0 Release Candidate includes some new options for the &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;has_one&lt;/code&gt; declarations.&lt;/p&gt;


	&lt;p&gt;Previously, you could do the following:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Customer&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_many&lt;/span&gt; &lt;span class="symbol"&gt;:orders&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:dependent&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="constant"&gt;true&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This was supposed to nullify the dependent records, but &lt;a href="http://dev.rubyonrails.com/ticket/2009"&gt;it didn&amp;#8217;t&lt;/a&gt;!&lt;/p&gt;


	&lt;p&gt;My patch not only fixes this, but also gives more control with what &lt;cod&gt;:dependent&lt;/code&gt; does. Now, you can pass the &lt;code&gt;:dependent&lt;/code&gt; option to the &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;has_one&lt;/code&gt; declarations with either &lt;code&gt;:nullify&lt;/code&gt; or &lt;code&gt;:destroy&lt;/code&gt;. This has a similar affect as &lt;code&gt;ON DELETE CASCADE&lt;/code&gt; in those fancy RDBMs like PostgreSQL.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s take a closer look at these new options:&lt;/p&gt;


	&lt;h2&gt;has_one&lt;/h2&gt;


	&lt;p&gt;A spider &lt;code&gt;has_one&lt;/code&gt; web, and the web &lt;code&gt;belongs_to&lt;/code&gt; one spider. If you destroy the spider, you would most likely want to destroy the web as well.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Spider&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_one&lt;/span&gt; &lt;span class="symbol"&gt;:web&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:dependent&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="symbol"&gt;:destroy&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;On the other hand, in the case of a snail that &lt;code&gt;has_one&lt;/code&gt; shell (and the one shell &lt;code&gt;belongs_to&lt;/code&gt; the snail), if you destroy the snail, you may want to keep the shell. Remember, your crazy Aunt Ruby collects snail shells.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Snail&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_one&lt;/span&gt; &lt;span class="symbol"&gt;:shell&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:dependent&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="symbol"&gt;:nullify&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Now, for every snail we destroy, the shells, though once dependent on the snail, are now available for Aunt Ruby.&lt;/p&gt;


	&lt;h2&gt;has_many&lt;/h2&gt;


	&lt;p&gt;The same rules apply to the &lt;code&gt;has_many&lt;/code&gt; association. Most people assume that if you destory a beehive that you would destroy all the bees. I&amp;#8217;d like to think that they wander around until they find a new beehive to join. So, we can &lt;code&gt;:nullify&lt;/code&gt; their relationship when the beehive is destroyed, thus making them homeless, but available for future hives.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Beehive&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_many&lt;/span&gt; &lt;span class="symbol"&gt;:bees&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:dependent&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="symbol"&gt;:nullify&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Sadly, some people might want to destroy the bees along with the destruction of the beehive. So, &lt;em&gt;those people&lt;/em&gt; can pass the &lt;code&gt;:dependent&lt;/code&gt; option,  &lt;code&gt;:destroy&lt;/code&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Beehive&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_many&lt;/span&gt; &lt;span class="symbol"&gt;:bees&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:dependent&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="symbol"&gt;:destroy&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Don&amp;#8217;t worry, your usage of &lt;code&gt;:dependent =&amp;gt; true&lt;/code&gt; will now work, even though it wasn&amp;#8217;t working before.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m going to try to put more trust into Active Record now, and I hope that this new addition to the library finds itself useful for you. :-)&lt;/p&gt;


	&lt;p&gt;Take a peak at the cool &lt;a href="http://documentation.rubyonrails.com/release_notes/rc2.html"&gt;new features&lt;/a&gt; in the latest version of Rails and see the &lt;a href="http://api.rubyonrails.com/files/vendor/rails/activerecord/CHANGELOG.html"&gt;Active Record &lt;span class="caps"&gt;CHANGELOG&lt;/span&gt;&lt;/a&gt; for more information.&lt;/p&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;
</description>
      <pubDate>Wed, 19 Oct 2005 18:00:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c9cc19af4007d50c22cf5dbfb39c280c</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/19/new-active-record-options-for-associations</link>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>rails</category>
      <category>activerecord</category>
      <category>databases</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>A PostgreSQL tip</title>
      <description>&lt;p&gt;&lt;em&gt;I promised that I would send a link out or something&amp;#8230; so here goes.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;Tonight at the Portland Ruby Brigade meeting, the question about having Active Record &lt;span class="caps"&gt;READ&lt;/span&gt; from one database and &lt;span class="caps"&gt;WRITE&lt;/span&gt; to another database was brought up. The discussion was going in the route of, &amp;#8220;How can we make AR do this?&amp;#8221;&lt;/p&gt;


	&lt;p&gt;I chimed in with my usual PostgreSQL bias. &amp;#8220;pgpool.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Let something else handle this. Infact, with PgPool, you don&amp;#8217;t have to change any code in your Rails application to make this work. :-)&lt;/p&gt;


	&lt;p&gt;So, take a look at: &lt;a href="http://pgpool.projects.postgresql.org"&gt;pgpool&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;
</description>
      <pubDate>Wed, 05 Oct 2005 01:07:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:43e51e300ec32450ac48111ebf90fb82</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/05/a-postgresql-tip</link>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>Portland Ruby Brigade meets CD Baby</title>
      <description>This is what happened to the &lt;a href="http://www.pdxruby.org"&gt;Portland Ruby Brigade&lt;/a&gt; today:
	&lt;ul&gt;
	&lt;li&gt;Got double booked on meeting night with the &lt;span class="caps"&gt;PHP&lt;/span&gt; group&lt;/li&gt;
		&lt;li&gt;Got asked to leave after getting threats of the lights being turned off&lt;/li&gt;
		&lt;li&gt;Stayed almost til closing time at a brew&amp;#8230; we heard, &amp;#8220;Last Call!&amp;#8221; and still continued talking&amp;#8230;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Tonight I finally got to meet &lt;a href="http://blog.bleything.net"&gt;Ben&lt;/a&gt;, &lt;a href="http://www.smallwhitecube.com/"&gt;Caleb&lt;/a&gt;, Justin Watkins, Marcus Estes, Lennon Day-Reynolds, Jeremy Kempter (bitsweat), Aaron Johnson, and Peat Bakke-&lt;del&gt;each for the first time. I also got to see &lt;a href="http://scottstuff.net/blog/"&gt;Scott Laird&lt;/a&gt; (of Typo fame) and John Labovitz again. Scott and I met at &lt;span class="caps"&gt;FOSCON&lt;/span&gt; and John once found me when he was trying to hack people at a coffee shop and saw that I was on the wireless network. Okay, he wasn&amp;#8217;t hacking&amp;#8230; but found me at Urban Grind. :&lt;/del&gt;)&lt;/p&gt;


	&lt;p&gt;We had about ~25 people show up. I don&amp;#8217;t think that there was a head count made. We sat around in a big circle and fired questions at both Derek Sivers and Jeremy Kemper. Topics ranged from how Derek found his way to PostgreSQL to why he thinks that he is an amazing web designer (&lt;strong&gt;smirk&lt;/strong&gt;) to why Ruby and Rails was picked as the platform to move to from a &lt;span class="caps"&gt;PHP&lt;/span&gt;/MySQL system. Jeremy shared some insights into some problems with Rails that need to be worked on (boolean-stuff for example), tips on debugging, and many other things that I don&amp;#8217;t recall off the top of my head.&lt;/p&gt;


	&lt;p&gt;It was a very relaxed and open conversation with some cool local developers who are working on getting their Rails/PostgreSQL system finished.&lt;/p&gt;


	&lt;p&gt;After we got kicked out of FreeGeek most of migrated to the Lucky Lab Pub&amp;#8230; and then we realized that Derek and Jeremy didn&amp;#8217;t show up. So, we found our ways to a big table and broke up into smaller conversations. I got &lt;strong&gt;stuck&lt;/strong&gt; at the table with Ben, Scott, Caleb, and John. Actually, it was quite enjoyable. Scott talked about his work with Typo and Ben and I gave him some of our thoughts on things.&lt;/p&gt;


	&lt;p&gt;This is a horrible summary of the whole evening. It&amp;#8217;s what I remember&amp;#8230; and it&amp;#8217;s late and I look forward to getting to hang out with this gang again in the future. I think that it was great to get to finally meet a few of the people that I have worked on some smaller projects with. If everything works out well, expect there to be some more projects coming out of the &lt;a href="http://www.pdx.rb"&gt;&lt;span class="caps"&gt;PDX&lt;/span&gt;.rb&lt;/a&gt; in the coming months. :-)&lt;/p&gt;


	&lt;p&gt;Thanks again to Derek Sivers and Jeremy Kemper for taking time out of their busy schedule to meet &amp;#38; greet with the Portland Ruby people. :-)&lt;/p&gt;
</description>
      <pubDate>Wed, 05 Oct 2005 00:25:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:954c23e7217b0bbc829592d04bf8402f</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/05/portland-ruby-brigade-meets-cd-baby</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>ruby</category>
      <category>rails</category>
      <category>programming</category>
      <category>cdbaby</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>The bitter-sweet taste of agnostic database schemas</title>
      <description>&lt;p&gt;If you know me at all by now&amp;#8230; you might know that I am a &lt;strong&gt;huge&lt;/strong&gt; fan of &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt;. Coming to the &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; camp  was a bit of an eye-opener./  Working with PostgreSQL used to save me quite a bit of work and let me sleep at night. I have dealt with the problems that &lt;a href="http://sql-info.de/mysql/gotchas.html"&gt;many developers face&lt;/a&gt; while working with &lt;a href="http://www.mysql.com"&gt;MySQL&lt;/a&gt;. Like many of us in the Open Source world, I was exposed to MySQL more often than PostgreSQL. For several years, I convinced myself that MySQL was awesome because it was fast&amp;#8230; but &lt;a href="http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/LanguageChoice.rdoc"&gt;speed isn&amp;#8217;t always&lt;/a&gt; the most important factor in the technology world. Otherwise, we&amp;#8217;d all be coding in C. What PostgreSQL provided to me as a developer was better relational integrity. Foo cannot exist unless Bar does, or vice versa. &lt;code&gt;ON DELETE CASCADE&lt;/code&gt; was a godsend and saved me quite a bit of work when building an application. Triggers&amp;#8230; Procedural Languages&amp;#8230; &lt;a href="http://www.robbyonrails.com/articles/tag/plruby"&gt;oh so beautiful&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;PostgreSQL was (and is) the Open Source database server that both the &lt;strong&gt;Enterprise&lt;/strong&gt; DBA and Developer could agree on.&lt;/h3&gt;


	&lt;h3&gt;Enter Ruby on Rails&lt;/h3&gt;


	&lt;p&gt;At first, I just ignored my instincts and jumped in head first. &lt;strong&gt;Pluralization&lt;/strong&gt;?  Primary keys named &lt;code&gt;id&lt;/code&gt;? &lt;strong&gt;Blasphemy&lt;/strong&gt;! Yet, I moved forward. After a few days of consistently reminding myself of these new-fangled conventions (I even printed out a little cheat sheet and taped it to my monitor)... I was hooked. Rails worked with PostgreSQL. Let me say that again.&lt;/p&gt;


	&lt;h3&gt;&lt;span class="caps"&gt;RAILS WORKS WITH POSTGRESQL&lt;/span&gt;!&lt;/h3&gt;


	&lt;p&gt;Don&amp;#8217;t freak out. Yes, the person who started the Rails project is a &lt;a href="http://www.loudthinking.com/arc/000516.html"&gt;MySQL fan&lt;/a&gt;... but Rails is &lt;a href="http://weblog.rubyonrails.com/archives/2005/09/27/database-agnostic-schemas-with-migrations"&gt;database agnostic&lt;/a&gt;. It&amp;#8217;s true.&lt;/p&gt;


	&lt;p&gt;I wanted to write an entry to clear up a &lt;a href="http://people.planetpostgresql.org/xzilla/index.php?/archives/62-OSCon-Day-1-Evening-or-Ruby-on-Rails.html"&gt;few&lt;/a&gt; &lt;a href="http://blog.amber.org/2005/09/27/least-common-denominator/"&gt;myths&lt;/a&gt; about Rails.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Table names are &lt;strong&gt;not forced&lt;/strong&gt;&lt;/li&gt;
		&lt;li&gt;Primary Key field names are &lt;strong&gt;not forced&lt;/strong&gt;&lt;/li&gt;
		&lt;li&gt;Foriegn Key field names are &lt;strong&gt;not forced&lt;/strong&gt;&lt;/li&gt;
		&lt;li&gt;Legacy databases &lt;strong&gt;can&lt;/strong&gt; &lt;a href="http://www.robbyonrails.com/articles/2005/07/25/the-legacy-of-databases-with-rails"&gt;work with Rails&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Active Record (like much of Rails) &lt;strong&gt;can&lt;/strong&gt; be customized for your particular application&amp;#8217;s needs&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I was, and still am, concerned about trusting Active Record with handling my relational data&amp;#8230; because in some cases it &lt;a href="http://www.robbyonrails.com/articles/2005/08/18/active-record-i-3-u-but-i-still-trust-my-database-server-a-tiny-bit-more"&gt;wasn&amp;#8217;t doing what it should&lt;/a&gt;.   But, that is being worked on&amp;#8230; and because Rails is Open Source, the issue is transparent for us developers to see and help fix.&lt;/p&gt;


	&lt;p&gt;In the past, you might have found me advocating the addition of &lt;strong&gt;business logic&lt;/strong&gt; in your database server, whenever possible. &lt;em&gt;It is the gate keeper&lt;/em&gt;. The key master. It is not meant to be &lt;strong&gt;flexible&lt;/strong&gt; with your data. If business rules are to change, you change them there so that if you have one or more &lt;span class="caps"&gt;INPUT&lt;/span&gt; streams into your database, the data will not get into your server unless your business rules are met. PostgreSQL even provides you with a nice &lt;span class="caps"&gt;ERROR&lt;/span&gt; message, which some other servers do not. If you can control everything through one &lt;span class="caps"&gt;INPUT&lt;/span&gt; stream (&lt;a href="http://martinfowler.com/bliki/ApplicationDatabase.html"&gt;Application Database&lt;/a&gt;),  then putting these constraints solely in your database abstraction layer is a-ok. However, if you are interfacing with your server through a variety of avenues (&lt;a href="http://martinfowler.com/bliki/IntegrationDatabase.html"&gt;Integration Database&lt;/a&gt;),  you probably already know that your system is going to be a pain to maintain in the long run. So, what are you to do?&lt;/p&gt;


	&lt;p&gt;Handling Legacy systems is going to be a headache, regardless of what you do&amp;#8230; but you can&amp;#8217;t always rebuild the whole thing and migrate your data. Add that to &lt;a href="http://www.43folders.com/2005/09/building_a_smar.html"&gt;your Someday-Maybe list&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;When you&amp;#8217;re adding new pieces to your application, start by using &lt;a href="http://subversion.tigris.org/"&gt;good tools&lt;/a&gt;, &lt;a href="http://www.rubyonrails.org/"&gt;frameworks&lt;/a&gt;, and &lt;a href="http://www.pragmaticprogrammer.com/ppbook/index.shtml"&gt;practices&lt;/a&gt;. For example, try your best to follow the &lt;a href="http://martinfowler.com/bliki/ApplicationDatabase.html"&gt;Application Database&lt;/a&gt; path to &lt;em&gt;pragmatic enlightenment&lt;/em&gt;.  Begin working on a new layer for your legacy database. Add on web services that use this layer. Refactor your existing applications. Can they use these new services? &lt;strong&gt;ReThink everything&lt;/strong&gt;. That is&amp;#8230; if you have the time and resources to do so.&lt;/p&gt;


	&lt;p&gt;If you are questioning whether or not to put your business logic in your database abstraction layer, stop. Just do it&amp;#8482;. But, do it with caution. Test it. Test it well. I&amp;#8217;ll admit that I &lt;strong&gt;still&lt;/strong&gt; add some constraints into my database schemas-&lt;del&gt;I am not ready to give up that extra layer of data security. But, that&amp;#8217;s just me. :&lt;/del&gt;)&lt;/p&gt;


	&lt;h3&gt;PostgreSQL works with Rails!&lt;/h3&gt;


	&lt;p&gt;...and I promise to show you how to do some fun legacy stuff with Rails in my book. :-)&lt;/p&gt;
</description>
      <pubDate>Tue, 27 Sep 2005 08:41:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:7af17a431c8a1a0b1f1b471e9cb07e79</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/09/27/the-bitter-sweet-taste-of-agnostic-database-schemas</link>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>rails</category>
      <category>dhh</category>
      <category>postgresql</category>
    </item>
    <item>
      <title>Hurricane shelter uses Rails and PostgreSQL, thanks open source</title>
      <description>&lt;p&gt;I came across &lt;a href="http://www.sasafelist.org/?p=69"&gt;this weblog entry&lt;/a&gt; on a website that is offering shelter for victims of &lt;a href="http://en.wikipedia.org/wiki/Hurricane_Katrina"&gt;Hurricane Katrina&lt;/a&gt;.&lt;/p&gt;


The author writes:
&lt;blockquote&gt;
How do you measure the &lt;span class="caps"&gt;ROI&lt;/span&gt; on a project like this? How do I get PostgreSQL or Ruby-on-Rails credit for reuniting a twelve year-old girl with her father who had been missing for three weeks or any of the other amazing stories we heard everyday at Windsor?
&lt;/blockquote&gt;

	&lt;p&gt;It&amp;#8217;s great to hear that Open Source is used for situations like this. The money that would have been spent on commercial applications and support would be better spent on the people that they are trying to help.&lt;/p&gt;


	&lt;p&gt;I tried to figure out exactly which page might be using Rails (as they are using Gallery, WordPress, etc for a few other pieces of their system). I found &lt;a href="http://www.familylinks.icrc.org/katrina"&gt;this&lt;/a&gt;, which looks like it might be based in &lt;a href="http://www.rubyonrails.org/"&gt;Rails&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt; I couldn&amp;#8217;t find too much information about this, just their blog and a few links from it. If you find more information, please comment and I&amp;#8217;ll update this entry. :-)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;I got an email from Rudi Cilibrasi from &lt;a href="http://www.katrinahelp.info/"&gt;Katrina Help&lt;/a&gt;. They are using Ruby on Rails for their &lt;a href="http://www.katrinahelp.info/rdata/"&gt;people search&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Sat, 24 Sep 2005 07:45:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:97412be2eee3c6a3d32fa3648bb3dab5</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/09/24/shelter-uses-ruby-on-rails-and-postgresql-which-helps-reunite-12-year-old-girl-with-father</link>
      <category>Ruby on Rails</category>
      <category>PostgreSQL</category>
      <category>rails</category>
      <category>postgresql</category>
      <category>shelter</category>
    </item>
    <item>
      <title>CDBaby Q&amp;amp;A at next Portland Ruby Brigade meeting</title>
      <description>&lt;p&gt;I just posted on the &lt;a href="http://www.pdxruby.org/"&gt;Portland Ruby Brigade&lt;/a&gt; &lt;a href="http://blog.pdxruby.org/"&gt;blog&lt;/a&gt; that Derek Sivers and Jeremy Kemper (bitsweat) will be coming to the next &lt;a href="http://www.pdxruby.org/"&gt;&lt;span class="caps"&gt;PDX&lt;/span&gt;.rb&lt;/a&gt; user group meeting. Derek and Jeremy will field questions from all of us in regards to their complete rewrite of &lt;a href="http://www.cdbaby.com/"&gt;CD Baby&lt;/a&gt; from &lt;span class="caps"&gt;PHP&lt;/span&gt;+MySQL to Ruby+Rails+PostgreSQL. (my favorite open-source projects!)&lt;/p&gt;


	&lt;p&gt;This will take place at &lt;a href="http://www.freegeek.org/"&gt;FreeGeek&lt;/a&gt; in Portland, Oregon on October 4th, 2005!&lt;/p&gt;


	&lt;p&gt;For more information, see the &lt;a href="http://www.pdxruby.org/"&gt;Portland Ruby Brigade website&lt;/a&gt;&lt;/p&gt;
</description>
      <pubDate>Fri, 23 Sep 2005 15:06:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:6ce89b658c077919d3cc5d5479798790</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/09/23/cdbaby-q-a-at-next-portland-ruby-brigade-meeting</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PostgreSQL</category>
      <category>ruby</category>
      <category>rails</category>
      <category>postgresql</category>
      <category>cdbaby</category>
      <category>portland</category>
    </item>
    <item>
      <title>PL/Ruby loves RubyGems and DRb</title>
      <description>&lt;p&gt;I admit it. I have had a torrid love affair with procedural languages ever since I started playing with PostgreSQL. The ability to share logic amongst all the applications touching the same database server.. was…well… a breath of fresh air.&lt;/p&gt;


	&lt;p&gt;What is a procedural language in Postgresql?&lt;/p&gt;


	&lt;p&gt;PostgreSQL docs describe them as, ”&amp;#8230;allows user-defined functions to be written in other languages besides &lt;span class="caps"&gt;SQL&lt;/span&gt; and C. “&lt;/p&gt;


	&lt;p&gt;Well, PostgreSQL has PLs for Perl, Python, Java, C, &lt;span class="caps"&gt;PHP&lt;/span&gt;… and even &lt;span class="caps"&gt;RUBY&lt;/span&gt;!&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
CREATE FUNCTION ruby_max(int4, int4) RETURNS int4 AS '
    if args[0].to_i &amp;gt; args[1].to_i
        return args[0]
    else
        return args[1]
    end
' LANGUAGE 'plruby';
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;PL/PGSQL is nice and all, but it’s not as fun as playing with Ruby. PL/Perl… well is perl, and PL/Python… is python. Both PL/Perl and PL/Python have untrusted variants. You see, they don’t want your PostgreSQL server to do anything harmful to the machine by being able to do stuff like system(&amp;#8216;cat /dev/null &amp;gt; /etc/passwd). But for some people, (like me) they want the flexibility of their language anyways. :-)&lt;/p&gt;


	&lt;p&gt;Note: Never do this if your system user that runs PostgreSQL has privileges to do anything harmful on your system.&lt;/p&gt;


	&lt;p&gt;The PL/Ruby documentation is minimal at the moment, but covers enough to get you started. I don’t know if many people are using it out there… but hopefully that is about to change! I’ve played with it a bit, but always wanted to be able to do stuff like require &amp;#8216;rubygems&amp;#8217;, but this is a feature of an untrusted language. I even found myself digging around in C code to see if I could figure out how to hack the plruby language to skip over those checks… but I am not a C programmer and I got lost in some header files.&lt;/p&gt;


	&lt;p&gt;Then it hit me. “Why haven’t you emailed the author?”&lt;/p&gt;


	&lt;p&gt;So I emailed the author of PL/Ruby, Guy Decoux, who responded pretty quickly with the answer to my dreams! Okay, I do have bigger dreams than this… but you get the idea.&lt;/p&gt;


	&lt;p&gt;First of all, some of you might be thinking, ”Why on Earth would you want to do this?”&lt;/p&gt;


	&lt;p&gt;Well, here is a simple example of how it could be used with RedCloth Let’s say that I want to be able to perform the following query from within &lt;span class="caps"&gt;SQL&lt;/span&gt;.&lt;/p&gt;


&lt;typo:code lang=ruby"&gt;&lt;span class="caps"&gt;SELECT&lt;/span&gt; redcloth(&amp;#8216;&lt;strong&gt;strong text&lt;/strong&gt; and &lt;em&gt;emphasized text&lt;/em&gt;&amp;#8216;);&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Why not do this in the application? Well, I do actually have a case where I have an older &lt;span class="caps"&gt;PHP&lt;/span&gt; application that I will be porting to Ruby in the future, but would like to give the application some access to some of the features of Ruby that I will be using, such as RedCloth.&lt;/p&gt;


	&lt;p&gt;Okay, so show me an example of one of these scary PostgreSQL functions.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
CREATE FUNCTION redcloth(text) RETURNS text AS '

  require ''rubygems''
  require ''redcloth''

  content = args[0]

  rc = RedCloth.new(content)

  return rc.to_html

' LANGUAGE 'plruby';
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;”Wait! You said this would be scary!?”&lt;/p&gt;


	&lt;p&gt;Well, PL/Ruby allows you to write… plain ole Ruby within your functions. (do you see where I am getting here?)&lt;/p&gt;


	&lt;h2&gt;PL/Ruby meets RedCloth&lt;/h2&gt;


&lt;pre&gt;&lt;code&gt;
 rb=# SELECT redcloth('*strong text* and _emphasized text_');
                             redcloth
------------------------------------------------------------------
 &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;strong text&amp;lt;/strong&amp;gt; and &amp;lt;em&amp;gt;emphasized text&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;
(1 row)
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;PL/Ruby meets ShortURL&lt;/h2&gt;


&lt;pre&gt;&lt;code&gt;
CREATE FUNCTION rubyurlize(text) RETURNS text AS '

  require ''rubygems''
  require ''shorturl''

  return ShortURL.shorten(args[0])

' LANGUAGE 'plruby';
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;...which allows for&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
 rb=# SELECT
rb-#   rubyurlize('http://www.robbyonrails.com/') as link1,
rb-#   rubyurlize('http://moulon.inra.fr/ruby/plruby.html') as link2;
          link1           |         link2
--------------------------+------------------------
 http://rubyurl.com/lyoKm | http://rubyurl.com/dTo
(1 row)
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;PostgreSQL meets DRb&lt;/h2&gt;


	&lt;p&gt;Okay, this is one of the reasons why I wanted to play with PL/Ruby a bit more. Distributed Ruby Objects… from PostreSQL?&lt;/p&gt;


	&lt;h3&gt;What is DRb?&lt;/h3&gt;


	&lt;p&gt;If you don’t know already… per the description in &lt;span class="caps"&gt;RDOC&lt;/span&gt;, “dRuby is a distributed object system for Ruby. It allows an object in one Ruby process to invoke methods on an object in another Ruby process on the same or a different machine.”&lt;/p&gt;


	&lt;p&gt;It basically allows you to share an object to other machines… at the same time!&lt;/p&gt;


	&lt;p&gt;mmm…distributed objects…&lt;/p&gt;


	&lt;h3&gt;DRb Object&lt;/h3&gt;


	&lt;p&gt;Here is a simple ruby script that you would run from the shell. It creates a DRb object which accepts connections at localhost:9000.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
#!/usr/bin/ruby

require 'drb'

class MyRemoteObject
  def say(str)
    return "You say #{str}. I say #{str.reverse.upcase}!" 
  end
end

server = MyRemoteObject.new

DRb.start_service('druby://localhost:9000', server)
DRb.thread.join
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Start me up!&lt;/p&gt;


&lt;code&gt;$ ruby mydrb.rb&lt;/code&gt;

	&lt;p&gt;Now that we have DRb running and listening for connections…we need a client to connect to it.&lt;/p&gt;


	&lt;p&gt;DRb function in PL/Ruby&lt;/p&gt;


	&lt;p&gt;Here is a very simple DRb client script and I just drop that into a PostgreSQL function.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
CREATE FUNCTION drb_test(text) RETURNS text AS '

  require ''drb''

  DRb.start_service

  ro = DRbObject.new