<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-15618964</id><updated>2012-01-01T07:52:46.974-05:00</updated><title type='text'>Rubynating</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rubynating.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://rubynating.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Srivaths Sankaran</name><uri>https://profiles.google.com/107201414405071190918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-LDkgva69ZNE/AAAAAAAAAAI/AAAAAAAACkw/P8CjwA4e660/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-15618964.post-1122931406011337931</id><published>2007-01-11T11:20:00.000-05:00</published><updated>2007-01-11T13:34:09.490-05:00</updated><title type='text'>Rails Migrations aren't atomic</title><content type='html'>This note is applicable to Rails 1.1.6.5618 (which is really Rails 1.2 Release Candidate)&lt;br /&gt;&lt;br /&gt;If you use the migrations feature to keep track of and control schema changes, you should be aware that a migration involves two steps and that these aren't atomic.  This can come to bite you as we shall see.&lt;br /&gt;&lt;br /&gt;First, what are the two steps?&lt;br /&gt;&lt;br /&gt;Step 1: Make the changes to your application tables&lt;br /&gt;Step 2: Update the &lt;tt&gt;schema_info&lt;/tt&gt; table&lt;br /&gt;&lt;br /&gt;Suppose that your schema version is currently 3 i.e. the value of the &lt;tt&gt;version&lt;/tt&gt; field of the &lt;tt&gt;schema_info&lt;/tt&gt; table is 3.  Next say, you have developed the following schema change (&lt;tt&gt;004_add_create_date_and_usage.rb&lt;/tt&gt;)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;class AddCreateDateAndUsage &lt; ActiveRecord::Migration      &lt;br /&gt;    def self.up            &lt;br /&gt;        add_column :mytable, :created_at, :datetime            &lt;br /&gt;        add_column :mytable, :usage_count, number    &lt;br /&gt;    end      &lt;br /&gt;    def self.down            &lt;br /&gt;        remove_column :mytable, :created_at            &lt;br /&gt;        remove_column :mytable, :usage_count      &lt;br /&gt;    end&lt;br /&gt;end  &lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When you run this by issuing the command &lt;tt&gt;rake db:migrate&lt;/tt&gt; it will obviously fail when it tries to add the field &lt;tt&gt;usage_count&lt;/tt&gt; since &lt;tt&gt;number&lt;/tt&gt; is not a valid type.  The rake task quits at this stage.  If you check the database you will see that the table &lt;tt&gt;mytable&lt;/tt&gt; now has a &lt;tt&gt;created_at&lt;/tt&gt; field, no &lt;tt&gt;usage_count&lt;/tt&gt; field and that the &lt;tt&gt;schema_info&lt;/tt&gt; table says the version is still &lt;tt&gt;3&lt;/tt&gt;.   Oops!&lt;br /&gt;&lt;br /&gt;No problem, you think.  I'll just run &lt;tt&gt;rake db:migrate VERSION=3&lt;/tt&gt; and all will be back to the way it was.  You can then fix the mistake and run the migration again.  WRONG ANSWER!  &lt;br /&gt;&lt;br /&gt;The trouble is that since &lt;tt&gt;SCHEMA_INFO.VERSION=3&lt;/tt&gt; running &lt;tt&gt;rake db:migrate VERSION=3&lt;/tt&gt; does nothing!&lt;br /&gt;&lt;br /&gt;The way around it to manually edit the &lt;tt&gt;schema_info&lt;/tt&gt; table and set the value of &lt;tt&gt;version&lt;/tt&gt; to &lt;tt&gt;4&lt;/tt&gt; and then run &lt;tt&gt;rake db:migrate VERSION=3&lt;/tt&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15618964-1122931406011337931?l=rubynating.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rubynating.blogspot.com/feeds/1122931406011337931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15618964&amp;postID=1122931406011337931' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/1122931406011337931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/1122931406011337931'/><link rel='alternate' type='text/html' href='http://rubynating.blogspot.com/2007/01/rails-migrations-arent-atomic.html' title='Rails Migrations aren&apos;t atomic'/><author><name>Srivaths Sankaran</name><uri>https://profiles.google.com/107201414405071190918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-LDkgva69ZNE/AAAAAAAAAAI/AAAAAAAACkw/P8CjwA4e660/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15618964.post-115322935974253914</id><published>2006-07-18T09:18:00.000-04:00</published><updated>2006-07-18T10:52:45.540-04:00</updated><title type='text'>Rails views use GET requests to modify state</title><content type='html'>It is important to note that default views such as for a &lt;span style="font-family:courier new;"&gt;list&lt;/span&gt; action generated by Rails scaffolding breaks a &lt;a href="http://www.w3.org/DesignIssues/Axioms#state"&gt;cardinal rule of HTTP-based processing&lt;/a&gt; -- that a GET request shall not modify the state.  Said differently, one should be able to issue the same GET request any number of times and get the same response.&lt;br /&gt;&lt;br /&gt;If you look at the view generated for the &lt;span style="font-family:courier new;"&gt;list &lt;/span&gt;action, Rails uses a &lt;span style="font-family:courier new;"&gt;link_to&lt;/span&gt; tag on the RHTML page for the &lt;span style="font-family:courier new;"&gt;destroy &lt;/span&gt;action which results in a GET request being issued.  This has repercussions that go beyond the pedantic finger-wagging sermon on violating "cardinal rules".&lt;br /&gt;&lt;br /&gt;Consider a Rails application you have developed that includes the default view for listing Employees from the EMPLOYEES table.  The view includes a link each to edit and delete a given row.  Now if your web application URL is accessible by a web crawler, it will merrily crawl away your entire EMPLOYEES table!&lt;br /&gt;&lt;br /&gt;And no -- using a JavaScript confirmation isn't a safeguard since the web-crawler is like a user with JavaScript disabled!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15618964-115322935974253914?l=rubynating.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rubynating.blogspot.com/feeds/115322935974253914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15618964&amp;postID=115322935974253914' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/115322935974253914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/115322935974253914'/><link rel='alternate' type='text/html' href='http://rubynating.blogspot.com/2006/07/rails-views-use-get-requests-to-modify.html' title='Rails views use GET requests to modify state'/><author><name>Srivaths Sankaran</name><uri>https://profiles.google.com/107201414405071190918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-LDkgva69ZNE/AAAAAAAAAAI/AAAAAAAACkw/P8CjwA4e660/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15618964.post-112456361459962651</id><published>2005-08-20T23:57:00.000-04:00</published><updated>2005-08-20T20:57:43.210-04:00</updated><title type='text'>Getting Rails and MySQL to play nice</title><content type='html'>Working on my first Rails application has been quite an experience -- and not the kind you think.&lt;br /&gt;&lt;br /&gt;I've been following along with &lt;a href="http://www.pragmaticprogrammer.com/titles/rails/index.html"&gt;Dave Thomas' Rails book&lt;/a&gt;.  &lt;a href="http://www.pragmaticprogrammer.com/titles/rails/index.html"&gt; &lt;/a&gt;It provides a gentle introduction to the various Rails idioms and has proven handy. Following the spirit of the instructions, I created the necessary database and tables in my MySQL instance. Chapter 6 explains that in order for Rails to communicate with a database one has to specify connection settings in the &lt;span style="font-family:courier new;"&gt;config/database.yml&lt;/span&gt; file.  So, I provide the following&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;development:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  adapter: mysql&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  database: cc_dev&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  host: localhost&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  username:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  password:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I issued the command&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-weight: bold;"&gt;proj_root&gt;&lt;/span&gt; ruby script/generate scaffold Project Add&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;expecting it to create a &lt;span style="font-family:courier new;"&gt;Project &lt;/span&gt;model object (associated with the &lt;span style="font-family:courier new;"&gt;PROJECTS&lt;/span&gt; table that I had already created in MySQL) that would be accessed through the &lt;span style="font-family:courier new;"&gt;Add &lt;/span&gt;controller.  However, after a few create messages on the console, I got the following message:&lt;br /&gt;&lt;br /&gt;&lt;span class="279403105-20082005"&gt;&lt;span style=";font-family:Courier New;font-size:85%;"  &gt;No connection  could be made because the target machine actively refused it. -  connect(2)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Huh? Wasn't exactly the response I was expecting. I spent a long time trying various things such as: providing a username and password, providing an IP address instead of localhost etc, etc, I reached out to Google. There I came across &lt;a href="http://www.artima.com/forums/flat.jsp?forum=155&amp;thread=123317"&gt;a post &lt;/a&gt;by Jared Richardson on the same topic.  While my context was different it suggested a cure: comment out the line&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;skip-networking&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;in the &lt;span style="font-family:courier new;"&gt;my.cnf &lt;/span&gt;file.  Never having played in the bowels of MySQL, I found that on WinXP, that translates to &lt;span style="font-family:courier new;"&gt;the MYSQL_INSTALL_DIR\my.ini &lt;/span&gt;file. Since it did not say anything about skipping networking, I added it for good measure and commented it out by prefixing the line with a &lt;span style="font-family:courier new;"&gt;#&lt;/span&gt; character.  Still no dice.&lt;br /&gt;&lt;br /&gt;Now it just so happens that Jared's a colleague and a friend (small world). I wrote to him about my impasse and he suggested specifying the port in the &lt;span style="font-family:courier new;"&gt;database.yml &lt;/span&gt;file. I was skeptical -- since the Rails crowd had been drilling in the virtues of convention over configuration; I was thinking -- surely Rails would use defaults like with most other things. Anyway, I had wasted several hours on this problem and I had nothing to lose. So I added the line&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;port: 3306&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;so, my &lt;span style="font-family:courier new;"&gt;database.yml &lt;/span&gt;now looks like&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;development:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  adapter: mysql&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  database: cc_dev&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  host: localhost&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;port: 3306&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  username:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  password:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Paydirt!  Running the scaffold command again ran through to completion!  Hope that helps you and saves you few hours.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15618964-112456361459962651?l=rubynating.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rubynating.blogspot.com/feeds/112456361459962651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15618964&amp;postID=112456361459962651' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/112456361459962651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15618964/posts/default/112456361459962651'/><link rel='alternate' type='text/html' href='http://rubynating.blogspot.com/2005/08/getting-rails-and-mysql-to-play-nice.html' title='Getting Rails and MySQL to play nice'/><author><name>Srivaths Sankaran</name><uri>https://profiles.google.com/107201414405071190918</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-LDkgva69ZNE/AAAAAAAAAAI/AAAAAAAACkw/P8CjwA4e660/s512-c/photo.jpg'/></author><thr:total>14</thr:total></entry></feed>
