<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Blog of Heath</title>
	<atom:link href="http://heathanderson.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://heathanderson.wordpress.com</link>
	<description>My stuff and things go here</description>
	<lastBuildDate>Mon, 06 Sep 2010 20:58:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='heathanderson.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Blog of Heath</title>
		<link>http://heathanderson.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://heathanderson.wordpress.com/osd.xml" title="Blog of Heath" />
	<atom:link rel='hub' href='http://heathanderson.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Blog Has Moved!</title>
		<link>http://heathanderson.wordpress.com/2010/09/06/blog-has-moved/</link>
		<comments>http://heathanderson.wordpress.com/2010/09/06/blog-has-moved/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 20:55:49 +0000</pubDate>
		<dc:creator>heathanderson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogofheath.com/?p=72</guid>
		<description><![CDATA[New address: http://www.heathanderson.net<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=72&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>New address: <a href="http://www.heathanderson.net">http://www.heathanderson.net</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/heathanderson.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/heathanderson.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/heathanderson.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=72&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://heathanderson.wordpress.com/2010/09/06/blog-has-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81f0b3e0c5da01fbeb0ca3743662f070?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">heathanderson</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby on Rails Plugin: string_encryption</title>
		<link>http://heathanderson.wordpress.com/2009/11/23/ruby-on-rails-plugin-string_encryption/</link>
		<comments>http://heathanderson.wordpress.com/2009/11/23/ruby-on-rails-plugin-string_encryption/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 17:42:44 +0000</pubDate>
		<dc:creator>heathanderson</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blogofheath.com/?p=62</guid>
		<description><![CDATA[This is a very simple Ruby on Rails plugin that allows easy encryption of strings. For the sake of simplicity there no customization. The only cipher used is ‘des-ede3-cbc’ (Triple DES using Cipher Block Chaining) . See my post on encrypting/decrypting a string with Ruby for more information. First install the plugin: Next we need [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=62&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a very simple Ruby on Rails plugin that allows easy encryption of strings. For the sake of simplicity there no customization. The only cipher used is ‘des-ede3-cbc’ (Triple DES using Cipher Block Chaining) . See my <a href="http://blogofheath.com/2009/09/25/ruby-string-encryption/">post </a> on encrypting/decrypting a string with Ruby for more information. First install the plugin:</p>
<p><pre class="brush: ruby;">
 script/plugin install git://github.com/handerson/string_encryption.git
</pre> </p>
<p>Next we need to add an encryption key as the constant <code>ENV['STRING_ENCRYPTION_KEY']</code>. To do this just run<br />
<pre class="brush: ruby;">
 script/generate encryption_key
</pre><br />
or you could set<br />
<pre class="brush: ruby;">
ENV['STRING_ENCRYPTION_KEY'] = &quot;somekey&quot;
</pre><br />
where &#8220;somekey&#8221; is your key in environment.rb.</p>
<p>Now encryption/decryption is easy.</p>
<p>Encryption:<br />
<pre class="brush: ruby;">
&quot;Test&quot;.encrypt  #=&gt; &quot;NDFkZTc5NDEyNTg1MzdiZPzBrxZz5aoN%0A&quot;
</pre><br />
Decryption:<br />
<pre class="brush: ruby;">
&quot;NDFkZTc5NDEyNTg1MzdiZPzBrxZz5aoN%0A&quot;.decrypt  #=&gt; &quot;Test&quot;
</pre> </p>
<p>Code at Github:<br />
<a href="http://github.com/handerson/string_encryption">http://github.com/handerson/string_encryption</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/heathanderson.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/heathanderson.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/heathanderson.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=62&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://heathanderson.wordpress.com/2009/11/23/ruby-on-rails-plugin-string_encryption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81f0b3e0c5da01fbeb0ca3743662f070?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">heathanderson</media:title>
		</media:content>
	</item>
		<item>
		<title>Initialization Vector Length in MRI Ruby versus JRuby</title>
		<link>http://heathanderson.wordpress.com/2009/09/27/initialization-vector-length-in-mri-ruby-versus-jruby/</link>
		<comments>http://heathanderson.wordpress.com/2009/09/27/initialization-vector-length-in-mri-ruby-versus-jruby/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 18:22:56 +0000</pubDate>
		<dc:creator>heathanderson</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[JRuby]]></category>

		<guid isPermaLink="false">http://blogofheath.com/?p=52</guid>
		<description><![CDATA[When using OpenSSL encryption in standard Ruby, the length of an initialization vector (IV) can apparently be as large as you want it to be as long as it is at least the minimum size. This is odd. This can also cause trouble when switching over to JRuby. JRuby appear to be much pickier about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=52&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When using OpenSSL encryption in standard Ruby, the length of an initialization vector (IV) can apparently be as large as you want it to be as long as it is at least the minimum size. This is odd. This can also cause trouble when switching over to JRuby. JRuby appear to be much pickier about IV length.</p>
<p>This works in MRI but not in JRuby:</p>
<p><pre class="brush: ruby;">
unencrypted_data = &quot;test&quot;

des = OpenSSL::Cipher::Cipher.new(&quot;des-ede3-cbc&quot;)
des.encrypt
des.key = '0123456789abcdef01234567890'

des.iv = &quot;ed87acdcca419954edccb736f7dc77a74f5ac8dfe3861c3d5f77248e21592131a5423d63ff91f07956ce1aa386f8359931b5&quot; # 100 characters
encrypted_data = des.update(unencrypted_data) + des.final

puts encrypted_data
</pre></p>
<p>JRuby gives you this very helpful message:<br />
<code>ruby_string_encryption.rb:27:in `encrypt': No message available (OpenSSL::Cipher::CipherError)<br />
from ruby_string_encryption.rb:37</code></p>
<p>Change the IV to 8 characters and everything works fine.</p>
<p><strong>Update 10/14/2009</strong> The code that I originally posted was incorrect. I have updated it. Also I opened a <a href="http://jira.codehaus.org/browse/JRUBY-4012">ticket </a>for this issue. </p>
<p>If you are looking for what size an initialization vector should be check out my post on <a href="http://blogofheath.com/2009/09/25/ruby-string-encryption/">encrypting a string with Ruby</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/heathanderson.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/heathanderson.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/heathanderson.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=52&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://heathanderson.wordpress.com/2009/09/27/initialization-vector-length-in-mri-ruby-versus-jruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81f0b3e0c5da01fbeb0ca3743662f070?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">heathanderson</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby String Encryption</title>
		<link>http://heathanderson.wordpress.com/2009/09/25/ruby-string-encryption/</link>
		<comments>http://heathanderson.wordpress.com/2009/09/25/ruby-string-encryption/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 18:23:49 +0000</pubDate>
		<dc:creator>heathanderson</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Encryption]]></category>

		<guid isPermaLink="false">http://blogofheath.com/?p=29</guid>
		<description><![CDATA[Encrypting a string is fairly easy in Ruby. All you need to do is require 'openssl'. For this example I am using the &#8216;des-ede3-cbc&#8217; (Triple DES using Cipher Block Chaining) cipher. Most&#8211;if not all&#8211;of the ciphers listed on OpenSSL.org as supported ciphers should work as well. Triple DES requires a 24-byte key, with Ruby this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=29&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Encrypting a string is fairly easy in Ruby. All you need to do is <code>require 'openssl'</code>. For this example I am using the &#8216;des-ede3-cbc&#8217; (<a href="http://en.wikipedia.org/wiki/Triple_des">Triple DES</a> using <a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation">Cipher Block Chaining</a>) cipher. Most&#8211;if not all&#8211;of the ciphers listed on <a href="http://www.openssl.org/docs/apps/enc.html">OpenSSL.org</a> as supported ciphers should work as well.<br />
<span id="more-29"></span><br />
Triple DES requires a 24-byte key, with Ruby this means a string with 24 characters. We are also required to provide an <a href="http://en.wikipedia.org/wiki/Initialization_vector">initialization vector</a> (IV). The IV is usually the same size as the block size of the cipher you are using (so says Wikipedia, so say we all). In our case this means an IV of 64-bits, or 8-bytes, or an 8 character Ruby String. If we randomize our IV and include it with our encrypted string then we can ensure that our encrypted data never looks the same even when we encrypt the same string multiple times.</p>
<p><pre class="brush: ruby;">
require 'openssl'

KEY = '0123456789abcdef01234567890' # 24 characters

string = &quot;encrypt this&quot;

des = OpenSSL::Cipher::Cipher.new(&quot;des-ede3-cbc&quot;)
des.encrypt # this tells OpenSSL what mode to operate in, here we want to encrypt data
des.iv = iv = '01234567' # 8 characters, hard-coded for now

data = des.update(string) + des.final  
data = iv + data # this way when we randomize our IV it will be available when we need to decrypt the data

puts data
</pre></p>
<p>This should output something like <code>01234567z4¥K½ß) ©ˆˆ˜ž</code>. This isn&#8217;t the friendliest way to send data, so lets do something about that. The easiest thing to do is Base 64 encode the data, and maybe <a href="http://snippets.dzone.com/posts/show/1260">URI escape</a> it for good measure.</p>
<p><pre class="brush: ruby;">
# be sure to put the following at the top of your code:
# require &quot;base64&quot;
# require 'uri'
# after 'the puts data' in the snippet above do the following:

data = Base64.encode64(data)
data = URI.escape(data, Regexp.new(&quot;[^#{URI::PATTERN::UNRESERVED}]&quot;))

puts data
</pre></p>
<p>This should give you the much nicer <code>MDEyMzQ1Njd6jzSlS73fKSAdqYgRiJie%0A</code>.</p>
<p>Decryption is similarly easy.<br />
<pre class="brush: ruby;">
des = OpenSSL::Cipher::Cipher.new(&quot;des-ede3-cbc&quot;)
des.decrypt
des.key = KEY
encrypted_data = URI.unescape(data)
encrypted_data = Base64.decode64(data)
des.iv =  encrypted_data.slice!(0,8) #This gives us our iv back and removes it from the encrypted data
  
decrypted = des.update(encrypted_data) + des.final  
    
puts decrypted
</pre></p>
<p>If you are using Rails or have access to ActiveSupport <a href="http://api.rubyonrails.org/classes/ActiveSupport/SecureRandom.html">ActiveSupport::SecureRandom</a> is a great way to generate your key and IV. Also be sure to check out <a href="http://api.rubyonrails.org/classes/ActiveSupport/MessageEncryptor.html">ActiveSupport::MessageEncryptor</a> and my <a href="http://github.com/handerson/string_encryption">string_encryption</a> plugin. I&#8217;ll probably do a writeup on the string_encryption plugin sometime next week.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/heathanderson.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/heathanderson.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/heathanderson.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=29&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://heathanderson.wordpress.com/2009/09/25/ruby-string-encryption/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81f0b3e0c5da01fbeb0ca3743662f070?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">heathanderson</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby on Rails Plugin: data_migration</title>
		<link>http://heathanderson.wordpress.com/2009/09/22/ruby-on-rails-plugin-data_migration/</link>
		<comments>http://heathanderson.wordpress.com/2009/09/22/ruby-on-rails-plugin-data_migration/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 01:26:12 +0000</pubDate>
		<dc:creator>heathanderson</dc:creator>
				<category><![CDATA[Knetwit]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Migrations]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://heathanderson.wordpress.com/?p=5</guid>
		<description><![CDATA[data_migration allows you to separate data you need to load from your normal database migrations in a minimal way. While developing the new version of our flagship site, Knetwit, we decided we needed to separate our data migrations (initial settings and the like) from our structural migrations. We decided the easiest way to do this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=5&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>data_migration allows you to separate data you need to load from your normal database migrations in a minimal way. While developing the new version of our flagship site, <a href="http://www.knetwit.com">Knetwit</a>, we decided we needed to separate our data migrations (initial settings and the like) from our structural migrations. We decided the easiest way to do this was to modify the existing Rails migration to allow for a new data migration. So we did.</p>
<p>Install Plugin<br />
<pre class="brush: ruby;">script/plugin install git://github.com/handerson/data_migration.git</pre></p>
<p>Generate Migration<br />
<pre class="brush: ruby;">script/generate data_migration BlockedDomains</pre></p>
<p><pre class="brush: ruby;">exists  db/data
create  db/data/20090915161242_settings.rb</pre></p>
<p>db/data/20090915161242_settings.rb:<br />
<pre class="brush: ruby;">
class BlockedDomains &amp;lt; ActiveRecord::Migration
  def self.up
  end
end
</pre></p>
<p>Add your data:<br />
<pre class="brush: ruby;">
def self.up
  BlockedEmailDomain.create(:domain =&gt; &quot;mailinator.com&quot;)
  BlockedEmailDomain.create(:domain =&gt; &quot;spamherelots.com&quot;)
  BlockedEmailDomain.create(:domain =&gt; &quot;disposeamail.com&quot;)
end
</pre></p>
<p>Run Migration<br />
<pre class="brush: ruby;">rake db:data:migrate</pre><br />
<pre class="brush: ruby;">
==  BlockedDomains: migrating ===========================================================
==  BlockedDomains: migrated (0.0020s) ==================================================
</pre></p>
<p>db:data:migrate adds the data migration version number to the &#8216;schema_migrations&#8217; table so it will not be ran again.</p>
<p>Code at Github:<br />
<a href="http://github.com/handerson/data_migration">http://github.com/handerson/data_migration</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/heathanderson.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/heathanderson.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/heathanderson.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=heathanderson.wordpress.com&amp;blog=6400777&amp;post=5&amp;subd=heathanderson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://heathanderson.wordpress.com/2009/09/22/ruby-on-rails-plugin-data_migration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/81f0b3e0c5da01fbeb0ca3743662f070?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">heathanderson</media:title>
		</media:content>
	</item>
	</channel>
</rss>
