<?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/"
	>

<channel>
	<title>Kabisa Blog &#187; Ruby on Rails</title>
	<atom:link href="http://blog.kabisa.nl/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kabisa.nl</link>
	<description>The Ruby on Rails Experts</description>
	<lastBuildDate>Sun, 09 Oct 2011 07:54:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Long running migrations? Use the right tool for the job!</title>
		<link>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/</link>
		<comments>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/#comments</comments>
		<pubDate>Thu, 19 May 2011 07:47:29 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=187</guid>
		<description><![CDATA[Rails migrations are awesome, even for updating data after a migration to keep everything consistent. Arguably, you should not update data in migrations, but it is useful in some scenarios. If done incorrectly, however, data migrations can take a long time, causing unnecessary downtime of your application. The Problem Updating data can take a very [...]]]></description>
			<content:encoded><![CDATA[<p>Rails migrations are awesome, even for updating data after a migration to keep everything consistent. Arguably, you should not update data in migrations, but it is useful in some scenarios. If done incorrectly, however, data migrations can take a long time, causing unnecessary downtime of your application.<br />
<span id="more-187"></span></p>
<h2>The Problem</h2>
<p>Updating data can take a <em>very</em> long time, especially if done incorrectly. Consider the following example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Photo.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>photo<span style="color:#006600; font-weight:bold;">|</span>
  photo.<span style="color:#9900CC;">update_attribute</span> <span style="color:#ff3333; font-weight:bold;">:order</span>, <span style="color:#006666;">999</span> <span style="color:#9966CC; font-weight:bold;">if</span> photo.<span style="color:#9900CC;">order</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This might look nice and all and work okay on your development machine. However, if you run this on your production database with 78k photos&#8230; </p>
<p>You guessed it, it takes for ever. What happens is that Rails will fetch all photos from the database and instantiate 78k Photo objects. Then for each object it will issue an update-query if necessary. </p>
<p>Running this took at least ten minutes or more. Bad!</p>
<h2>The Alternative</h2>
<p>There is, luckily, an alternative that is quite a bit faster.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Photo.<span style="color:#9900CC;">update_all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;`order` = 999&quot;</span>, <span style="color:#996600;">&quot;`order` IS NULL&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This alternative issues exactly one update-query to the database and achieves the same end result as the previous code example. Also, this query took about 20 seconds to run!</p>
<p>You may want to look into http://apidock.com/rails/ActiveRecord/Base/update_all/class for more information about the <code>update_all</code> method.</p>
<h2>Conclusion</h2>
<p>Thinking about the code you put in your migrations, especially when manipulating data, is very important and will pay you back in less database downtime during deployments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to setup Ruby on Rails, Apache and Passenger on Debian Linux</title>
		<link>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/</link>
		<comments>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:05:05 +0000</pubDate>
		<dc:creator>Harm</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=40</guid>
		<description><![CDATA[For this article I&#8217;m going to install a single (virtual) server to run a standard Ruby on Rails application. I will be using Apache2 and passenger for the webserver stack and MySQL as a database server. Let&#8217;s start by installing Ruby and all tools: # apt-get install build-essential # apt-get install ruby irb ri rdoc [...]]]></description>
			<content:encoded><![CDATA[<p>For this article I&#8217;m going to install a single (virtual) server to run a standard Ruby on Rails application. I will be using Apache2 and passenger for the webserver stack and MySQL as a database server. </p>
<p>Let&#8217;s start by installing Ruby and all tools:</p>
<pre><code>
# apt-get install build-essential
# apt-get install ruby irb ri rdoc libopenssl-ruby ruby1.8-dev
# ruby -v
# cd /usr/local/src
# wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz # replace with latest version of rubygems
# tar xfvz rubygems-1.3.5.tgz
# cd rubygems-1.3.5
# ruby setup.rb
# ln -s /usr/bin/gem1.8 /usr/bin/gem
# gem -v
# gem install gemcutter
# gem tumble
# apt-get install mysql-server # this will ask for a password during installation
# apt-get install libmysqlclient15-dev
# gem install mysql
# gem install rails
# apt-get install git-core
# apt-get install apache2
# gem install passenger
# passenger-install-apache2-module</code></pre>
<p>Copy the following lines from the output and paste them at the end of the file /etc/apache2/apache2.conf. They should look something like this:</p>
<pre><code>
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.7
PassengerRuby /usr/bin/ruby1.8
</code></pre>
<p>Finally let&#8217;s restart apache2: </p>
<pre><code>/etc/init.d/apache2 restart</pre>
<p></code></p>
<p>Phew! That's it... We now have all the software we need on the server that's required to deploy your Ruby on Rails app on Debian Linux (Lenny)!</p>
<p>In a future article I'll cover the basics of deployment using <a href="http://capify.org">Capistrano</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

