<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Rails Worst Practices: 13 Coding Nightmares You Should Avoid</title>
	<atom:link href="http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/</link>
	<description>Running commentary about agile development, user experience design and Ajax.</description>
	<lastBuildDate>Thu, 18 Feb 2010 11:41:17 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Jason Roelofs</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-5753</link>
		<dc:creator>Jason Roelofs</dc:creator>
		<pubDate>Tue, 03 Feb 2009 05:00:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-5753</guid>
		<description>Great post, I agree with pretty much everything, but there&#039;s one part of #13 that no-one hear has touched on yet: testing. 

I need to write a data change migration (splitting data from one table into another table, and removing redundant columns). Given that the product is in production now, I must have a test that proves my migration works. So, how do I test my migration? I need to pull the database up to the point prior to the migration, setup some data, run the migration, then see that the results are correct. This requires that all previous migrations run fine, which is currently not the case (some old pure-data migrations are of course failing hard).

I&#039;ve been searching, talking with co-workers, I just don&#039;t know what the solution to this is. I&#039;ve personally always had the mindset that all migrations should be up- and down-able for this reason. Any one have suggestions here?</description>
		<content:encoded><![CDATA[<p>Great post, I agree with pretty much everything, but there&#8217;s one part of #13 that no-one hear has touched on yet: testing. </p>
<p>I need to write a data change migration (splitting data from one table into another table, and removing redundant columns). Given that the product is in production now, I must have a test that proves my migration works. So, how do I test my migration? I need to pull the database up to the point prior to the migration, setup some data, run the migration, then see that the results are correct. This requires that all previous migrations run fine, which is currently not the case (some old pure-data migrations are of course failing hard).</p>
<p>I&#8217;ve been searching, talking with co-workers, I just don&#8217;t know what the solution to this is. I&#8217;ve personally always had the mindset that all migrations should be up- and down-able for this reason. Any one have suggestions here?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Digitalia &#8211; Links For Wednesday 7th January 2009</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-5390</link>
		<dc:creator>Digitalia &#8211; Links For Wednesday 7th January 2009</dc:creator>
		<pubDate>Wed, 07 Jan 2009 19:14:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-5390</guid>
		<description>[...] Rails Worst Practices: 13 Coding Nightmares You Should Avoid Ostensibly for Rails, but most of these apply to anyone using an MVC framework, and are worth a look. (tags: programming webdev tips) [...]</description>
		<content:encoded><![CDATA[<p>[...] Rails Worst Practices: 13 Coding Nightmares You Should Avoid Ostensibly for Rails, but most of these apply to anyone using an MVC framework, and are worth a look. (tags: programming webdev tips) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Timberlake</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-5380</link>
		<dc:creator>Andrew Timberlake</dc:creator>
		<pubDate>Wed, 07 Jan 2009 15:12:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-5380</guid>
		<description>I must agree with those people arguing against #13.

One thing I will NEVER do is re-run a migration. A migration is a run-once and once only script (per database) and therefore I have no problem with it updating any of my database state whether schema or data.

Sometimes changing a schema requires setting data to a value such as adding a column and setting a &#039;default&#039; value based on existing data. A migration allows that to be done inline so that migrations can run one after each other without having to stop to run a rake task.

To clarify my run-once statement, once a database is in production, there is no way I&#039;m dropping and re-creating with migrations. It&#039;s live and must stay live so backups become the order of the day there.</description>
		<content:encoded><![CDATA[<p>I must agree with those people arguing against #13.</p>
<p>One thing I will NEVER do is re-run a migration. A migration is a run-once and once only script (per database) and therefore I have no problem with it updating any of my database state whether schema or data.</p>
<p>Sometimes changing a schema requires setting data to a value such as adding a column and setting a &#8216;default&#8217; value based on existing data. A migration allows that to be done inline so that migrations can run one after each other without having to stop to run a rake task.</p>
<p>To clarify my run-once statement, once a database is in production, there is no way I&#8217;m dropping and re-creating with migrations. It&#8217;s live and must stay live so backups become the order of the day there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Web Developer</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-5071</link>
		<dc:creator>Web Developer</dc:creator>
		<pubDate>Mon, 29 Dec 2008 19:06:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-5071</guid>
		<description>Nice post. But don&#039;t you think that you are are too dogmatic regarding some rules?</description>
		<content:encoded><![CDATA[<p>Nice post. But don&#8217;t you think that you are are too dogmatic regarding some rules?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4555</link>
		<dc:creator>Morgan</dc:creator>
		<pubDate>Thu, 18 Dec 2008 11:07:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4555</guid>
		<description>Greetings,
I know this is a week old (and I&#039;m loquacious, sorry), but I wanted to add a note about rule #13.  I have strong opinions about this one, having come off a project which did it a LOT, and having to be &#039;that guy&#039; who tried to encourage our new developers to avoid it.

I put migrations into three categories.  Structural changes (add/remove tables/columns, etc.), static data (a zip code to lat/long conversion table), and data (static or dynamic) changes (populate a new join table between users and topics).

Structural changes are what migrations are great at.  Use it and prosper.  (schema.rb is unfortunately usually shite in a big team in my experience, mainly due to conflicts, and its ever-changing nature.)

For static data, I have not yet found a good solution for bulk loading large amounts of static data into a newly created database, especially a test database (fixtures don&#039;t cut it for this stuff).  Rails just isn&#039;t built for that, and it&#039;s frustrating sometimes.  You end up in twisty little maze of implementations, all different.

Data changes are trouble, and I recommend against them as well.  You have two basic choices, either use the model (slow and harms refactorability) or direct SQL which bypasses your validations, so can lead to subtle data errors.

*I* feel #14 should be NEVER use models in your migrations.  If you find yourself tempted to use models in your migrations, you have clear evidence that you need a rake task.  A one-off rake task, perhaps, but a rake task.

I&#039;ve probably had a dozen models that I&#039;ve refactored away over the years that broke somebody&#039;s migration, and the only option was to go back and change their migration, which feels dirty for a reason.  :)

That said, I also believe that a fresh development database should always be creatable from the migrations and that you should set up CC.rb to do a migrate to create its databases.

A great back and forth related to this is on this very site at: http://www.pathf.com/blogs/2008/07/resolved-should-schemarb-be-included-in-your-source-control/

--  Morgan</description>
		<content:encoded><![CDATA[<p>Greetings,<br />
I know this is a week old (and I&#8217;m loquacious, sorry), but I wanted to add a note about rule #13.  I have strong opinions about this one, having come off a project which did it a LOT, and having to be &#8216;that guy&#8217; who tried to encourage our new developers to avoid it.</p>
<p>I put migrations into three categories.  Structural changes (add/remove tables/columns, etc.), static data (a zip code to lat/long conversion table), and data (static or dynamic) changes (populate a new join table between users and topics).</p>
<p>Structural changes are what migrations are great at.  Use it and prosper.  (schema.rb is unfortunately usually shite in a big team in my experience, mainly due to conflicts, and its ever-changing nature.)</p>
<p>For static data, I have not yet found a good solution for bulk loading large amounts of static data into a newly created database, especially a test database (fixtures don&#8217;t cut it for this stuff).  Rails just isn&#8217;t built for that, and it&#8217;s frustrating sometimes.  You end up in twisty little maze of implementations, all different.</p>
<p>Data changes are trouble, and I recommend against them as well.  You have two basic choices, either use the model (slow and harms refactorability) or direct SQL which bypasses your validations, so can lead to subtle data errors.</p>
<p>*I* feel #14 should be NEVER use models in your migrations.  If you find yourself tempted to use models in your migrations, you have clear evidence that you need a rake task.  A one-off rake task, perhaps, but a rake task.</p>
<p>I&#8217;ve probably had a dozen models that I&#8217;ve refactored away over the years that broke somebody&#8217;s migration, and the only option was to go back and change their migration, which feels dirty for a reason.  <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>That said, I also believe that a fresh development database should always be creatable from the migrations and that you should set up CC.rb to do a migrate to create its databases.</p>
<p>A great back and forth related to this is on this very site at: <a href="http://www.pathf.com/blogs/2008/07/resolved-should-schemarb-be-included-in-your-source-control/" rel="nofollow">http://www.pathf.com/blogs/2008/07/resolved-should-schemarb-be-included-in-your-source-control/</a></p>
<p>&#8211;  Morgan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel C</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4486</link>
		<dc:creator>Gabriel C</dc:creator>
		<pubDate>Tue, 16 Dec 2008 15:21:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4486</guid>
		<description>You can reduce rule 7 and 8 into one:
NEVER USE COPY &amp; PASTE!!!!
It shows laziness and lack of abstraction. Is a maintenance nightmare waiting to happen...</description>
		<content:encoded><![CDATA[<p>You can reduce rule 7 and 8 into one:<br />
NEVER USE COPY &amp; PASTE!!!!<br />
It shows laziness and lack of abstraction. Is a maintenance nightmare waiting to happen&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego Scataglini</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4478</link>
		<dc:creator>Diego Scataglini</dc:creator>
		<pubDate>Mon, 15 Dec 2008 18:05:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4478</guid>
		<description>I posted my comments here http://jroller.com/dscataglini/entry/rails_worst_practices_blanket_statements</description>
		<content:encoded><![CDATA[<p>I posted my comments here <a href="http://jroller.com/dscataglini/entry/rails_worst_practices_blanket_statements" rel="nofollow">http://jroller.com/dscataglini/entry/rails_worst_practices_blanket_statements</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Webiest : Bookmarks for December 14th through December 15th</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4474</link>
		<dc:creator>Webiest : Bookmarks for December 14th through December 15th</dc:creator>
		<pubDate>Mon, 15 Dec 2008 07:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4474</guid>
		<description>[...] Pathfinder Development &#187; Rails Worst Practices: 13 Coding Nightmares You Should Avoid - [...]</description>
		<content:encoded><![CDATA[<p>[...] Pathfinder Development &raquo; Rails Worst Practices: 13 Coding Nightmares You Should Avoid &#8211; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4468</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Sat, 13 Dec 2008 19:23:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4468</guid>
		<description>A thousand-line controller? Are you kidding me? A 100 LOC controller is too long.</description>
		<content:encoded><![CDATA[<p>A thousand-line controller? Are you kidding me? A 100 LOC controller is too long.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Aman</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4458</link>
		<dc:creator>Bob Aman</dc:creator>
		<pubDate>Fri, 12 Dec 2008 18:50:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4458</guid>
		<description>As an addendum to my above comment, when you get into tricky stuff, it pays to build migrations that are liberal in what they accept and conservative in what they produce.  Whatever the expected post-migration state of the database is for the normal case, should also be the expected post-migration state of the database for the exceptional case.  And if and only if you cannot possibly produce that expected state should your migration fail.</description>
		<content:encoded><![CDATA[<p>As an addendum to my above comment, when you get into tricky stuff, it pays to build migrations that are liberal in what they accept and conservative in what they produce.  Whatever the expected post-migration state of the database is for the normal case, should also be the expected post-migration state of the database for the exceptional case.  And if and only if you cannot possibly produce that expected state should your migration fail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Aman</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4457</link>
		<dc:creator>Bob Aman</dc:creator>
		<pubDate>Fri, 12 Dec 2008 18:42:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4457</guid>
		<description>Regarding migrations, I would say that while you&#039;re right that those are significant pain-points, I don&#039;t think I&#039;d go so far as to say that you should never do those things.  It&#039;s just that if you do those things, you MUST add error handling code to the migration, and anticipate each of the potential points of failure.  That&#039;s extra work of course, but I suspect that there are plenty of cases where your proposed solution ends up being even more work still.  It&#039;s one of those cases where it really pays to know what you&#039;re doing.</description>
		<content:encoded><![CDATA[<p>Regarding migrations, I would say that while you&#8217;re right that those are significant pain-points, I don&#8217;t think I&#8217;d go so far as to say that you should never do those things.  It&#8217;s just that if you do those things, you MUST add error handling code to the migration, and anticipate each of the potential points of failure.  That&#8217;s extra work of course, but I suspect that there are plenty of cases where your proposed solution ends up being even more work still.  It&#8217;s one of those cases where it really pays to know what you&#8217;re doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4455</link>
		<dc:creator>Anton</dc:creator>
		<pubDate>Fri, 12 Dec 2008 15:38:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4455</guid>
		<description>Correction : Rails sets up a sequence on Oracle for primary keys which starts at 10000, not 1001.</description>
		<content:encoded><![CDATA[<p>Correction : Rails sets up a sequence on Oracle for primary keys which starts at 10000, not 1001.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4453</link>
		<dc:creator>Anton</dc:creator>
		<pubDate>Fri, 12 Dec 2008 10:20:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4453</guid>
		<description>@Josh - I&#039;m not sure I follow the problem with your example exactly. If you are using object IDs in your migrations then I agree you are going to get yourself into massive trouble. Is that essentially what you are driving at?

In the environment I work with I couldn&#039;t do that anyway - I develop on MySQL but deploy to Oracle. The primary keys that Rails sets up on Oracle start at 1001 whereas on MySQL they start at 1. So right off the bat you couldn&#039;t even have migrations which used primary keys/object IDs.

So I&#039;d always be doing :

Faculty.find_by_code(&#039;SBS&#039;).update_attribute(:name, &#039;Southampton Business School&#039;)

...using a column (in this instance called code) which I know will never change, rather than...

Faculty.find(1001).update_attribute(:name, &#039;Southampton Business School&#039;)

...which is decidedly more risky and I wholeheartedly agree is a disaster waiting to happen.

Overall I think my view on what is acceptable/workable and what isn&#039;t is influenced by the fact I&#039;m usually the sole developer working on projects and I rule the database with an iron fist so (fingers crossed) I don&#039;t get any surprises.

If I was part of a large team where a lot of people could be interfering then perhaps my outlook on migrations would be different and my use of them would change. Still, it&#039;s useful to be aware of the potential pitfalls.</description>
		<content:encoded><![CDATA[<p>@Josh &#8211; I&#8217;m not sure I follow the problem with your example exactly. If you are using object IDs in your migrations then I agree you are going to get yourself into massive trouble. Is that essentially what you are driving at?</p>
<p>In the environment I work with I couldn&#8217;t do that anyway &#8211; I develop on MySQL but deploy to Oracle. The primary keys that Rails sets up on Oracle start at 1001 whereas on MySQL they start at 1. So right off the bat you couldn&#8217;t even have migrations which used primary keys/object IDs.</p>
<p>So I&#8217;d always be doing :</p>
<p>Faculty.find_by_code(&#8217;SBS&#8217;).update_attribute(:name, &#8216;Southampton Business School&#8217;)</p>
<p>&#8230;using a column (in this instance called code) which I know will never change, rather than&#8230;</p>
<p>Faculty.find(1001).update_attribute(:name, &#8216;Southampton Business School&#8217;)</p>
<p>&#8230;which is decidedly more risky and I wholeheartedly agree is a disaster waiting to happen.</p>
<p>Overall I think my view on what is acceptable/workable and what isn&#8217;t is influenced by the fact I&#8217;m usually the sole developer working on projects and I rule the database with an iron fist so (fingers crossed) I don&#8217;t get any surprises.</p>
<p>If I was part of a large team where a lot of people could be interfering then perhaps my outlook on migrations would be different and my use of them would change. Still, it&#8217;s useful to be aware of the potential pitfalls.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joran Greef</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4445</link>
		<dc:creator>Joran Greef</dc:creator>
		<pubDate>Thu, 11 Dec 2008 21:51:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4445</guid>
		<description>Thanks for the interesting points. Re: point 12:

&quot;If your application is going to be doing something non-standard, just don&#039;t bother with REST. Save yourself (and everyone else) a little bit of time.&quot;

I think you&#039;re a little misguided as to what REST actually is. If you&#039;re going to be doing something non-standard, just what exactly should you be bothering with? Wait.. a minute, I guess if you&#039;re doing something non-standard you&#039;re probably not doing REST. Yes, of course! :)</description>
		<content:encoded><![CDATA[<p>Thanks for the interesting points. Re: point 12:</p>
<p>&#8220;If your application is going to be doing something non-standard, just don&#8217;t bother with REST. Save yourself (and everyone else) a little bit of time.&#8221;</p>
<p>I think you&#8217;re a little misguided as to what REST actually is. If you&#8217;re going to be doing something non-standard, just what exactly should you be bothering with? Wait.. a minute, I guess if you&#8217;re doing something non-standard you&#8217;re probably not doing REST. Yes, of course! <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Britton</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4444</link>
		<dc:creator>Rob Britton</dc:creator>
		<pubDate>Thu, 11 Dec 2008 20:56:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4444</guid>
		<description>You&#039;re correct in some cases with #6, however many times you&#039;re just putting off the problem. This is violating the pragmatic concept of crashing early. As ActsAsFlinn says, it could be because of bad data or something like that. Just sticking andand everywhere will mask problems and they will creep up elsewhere. Before sticking andand somewhere you should think to yourself, &quot;should this value ever be nil?&quot; and if not, do not stick an andand there. Use andand in cases where nil is a valid value.</description>
		<content:encoded><![CDATA[<p>You&#8217;re correct in some cases with #6, however many times you&#8217;re just putting off the problem. This is violating the pragmatic concept of crashing early. As ActsAsFlinn says, it could be because of bad data or something like that. Just sticking andand everywhere will mask problems and they will creep up elsewhere. Before sticking andand somewhere you should think to yourself, &#8220;should this value ever be nil?&#8221; and if not, do not stick an andand there. Use andand in cases where nil is a valid value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Symonds</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4441</link>
		<dc:creator>Josh Symonds</dc:creator>
		<pubDate>Thu, 11 Dec 2008 18:34:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4441</guid>
		<description>Thanks for the positive commentary!

Scott, I think that you and I are actually agreeing on a lot of these points... at least, that&#039;s the impression I get from your comments. You say you don&#039;t agree with using migrations to load default data: that&#039;s pretty well what I&#039;m saying here. Put them in a separate file. Load them from migrations with rake tasks.

Your point that migrations should represent deltas is completely correct. You should never go back and change existing migrations. But that&#039;s one of the two options available to you when you have your data in your migrations: and opposed to the other one, it&#039;s the only way you can be 100% sure that the data is inserted correctly without failure. But I think you can see why this is a really bad idea.

The other option is having a migration only to change data existing in the database. This makes two huge assumptions that may prove unfounded: that the data exists and that it hasn&#039;t been changed already. If you&#039;re on a project with a lot of people, inserting such a dubious migration into the application is a sure way to make lots of exciting new enemies.

I&#039;m actually surprised I&#039;m getting a lot of pushback about #13, and you guys do have some really good points about it. Consider this, then: let&#039;s say you have a model Faculty that has and belongs to many Teachers (to shamelessly steal part of your example, Anton). You decide to insert a join model between them called Tenures, and you drop the old faculties_teachers table. You suddenly lose all your associations between Faculty and Teachers. So, before you do this, you have to prepopulate the Tenures table with the appropriate faculty_id and teacher_id. Now the static data in your migration no longer represents the actual state of your data.

If you had a rake task to generate Faculties, Teachers, and the relationship between them, though, it&#039;s unlikely anything at all would change in that task: it would still be able to do faculty.teachers &lt;&lt; teacher so nothing would change.

I guess my point is that static data tends not to be as static as one thinks. If you have data that is literally totally immutable, then go ahead and put it in a migration. But I&#039;ve come across very little that is literally totally immutable, and by putting data in a migration you risk the data integrity of your project. Rake tasks that run after migrations are a lot safer, more repeatable, and require less work on your part.

So that&#039;s the reasoning behind #13.</description>
		<content:encoded><![CDATA[<p>Thanks for the positive commentary!</p>
<p>Scott, I think that you and I are actually agreeing on a lot of these points&#8230; at least, that&#8217;s the impression I get from your comments. You say you don&#8217;t agree with using migrations to load default data: that&#8217;s pretty well what I&#8217;m saying here. Put them in a separate file. Load them from migrations with rake tasks.</p>
<p>Your point that migrations should represent deltas is completely correct. You should never go back and change existing migrations. But that&#8217;s one of the two options available to you when you have your data in your migrations: and opposed to the other one, it&#8217;s the only way you can be 100% sure that the data is inserted correctly without failure. But I think you can see why this is a really bad idea.</p>
<p>The other option is having a migration only to change data existing in the database. This makes two huge assumptions that may prove unfounded: that the data exists and that it hasn&#8217;t been changed already. If you&#8217;re on a project with a lot of people, inserting such a dubious migration into the application is a sure way to make lots of exciting new enemies.</p>
<p>I&#8217;m actually surprised I&#8217;m getting a lot of pushback about #13, and you guys do have some really good points about it. Consider this, then: let&#8217;s say you have a model Faculty that has and belongs to many Teachers (to shamelessly steal part of your example, Anton). You decide to insert a join model between them called Tenures, and you drop the old faculties_teachers table. You suddenly lose all your associations between Faculty and Teachers. So, before you do this, you have to prepopulate the Tenures table with the appropriate faculty_id and teacher_id. Now the static data in your migration no longer represents the actual state of your data.</p>
<p>If you had a rake task to generate Faculties, Teachers, and the relationship between them, though, it&#8217;s unlikely anything at all would change in that task: it would still be able to do faculty.teachers << teacher so nothing would change.</p>
<p>I guess my point is that static data tends not to be as static as one thinks. If you have data that is literally totally immutable, then go ahead and put it in a migration. But I&#8217;ve come across very little that is literally totally immutable, and by putting data in a migration you risk the data integrity of your project. Rake tasks that run after migrations are a lot safer, more repeatable, and require less work on your part.</p>
<p>So that&#8217;s the reasoning behind #13.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsled</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4440</link>
		<dc:creator>jsled</dc:creator>
		<pubDate>Thu, 11 Dec 2008 18:15:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4440</guid>
		<description>If you think REST is limited to applications that exclusively do &quot;CRUD&quot;-style operations … I think you misunderstand REST. There&#039;s nothing that says a resource must support all the HTTP methods, or that hypertext can&#039;t direct a client to to something decidedly un-CRUD-y. Perhaps you can expand on this point, a bit? (Honestly curious what you mean. :)</description>
		<content:encoded><![CDATA[<p>If you think REST is limited to applications that exclusively do &#8220;CRUD&#8221;-style operations … I think you misunderstand REST. There&#8217;s nothing that says a resource must support all the HTTP methods, or that hypertext can&#8217;t direct a client to to something decidedly un-CRUD-y. Perhaps you can expand on this point, a bit? (Honestly curious what you mean. <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ActsAsFlinn</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4438</link>
		<dc:creator>ActsAsFlinn</dc:creator>
		<pubDate>Thu, 11 Dec 2008 14:26:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4438</guid>
		<description>While I agree with most of this, I disagree with #6.  It contradicts the never rescue everything point raised first.  If you expect not to have a nil but you do have a nil there is a reason and that is probably not an esoteric mystery.  It&#039;s probably that you have bad data because you didn&#039;t validate input or that you have bad logic that results in your expectation isn&#039;t met.  andand and try seem to gloss this over.  Let&#039;s fix the root cause and not lower our expectations.</description>
		<content:encoded><![CDATA[<p>While I agree with most of this, I disagree with #6.  It contradicts the never rescue everything point raised first.  If you expect not to have a nil but you do have a nil there is a reason and that is probably not an esoteric mystery.  It&#8217;s probably that you have bad data because you didn&#8217;t validate input or that you have bad logic that results in your expectation isn&#8217;t met.  andand and try seem to gloss this over.  Let&#8217;s fix the root cause and not lower our expectations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua Slayton</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4435</link>
		<dc:creator>Joshua Slayton</dc:creator>
		<pubDate>Thu, 11 Dec 2008 11:21:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4435</guid>
		<description>Interesting and well thought out list. After about a solid year of Rails development, I think I may agree with all of your rules except for #13. A lot of the sites I work on deal with a static set of data, mostly geographic data - data that will never change. The data is prepared and generated once, then dumped into an SQL file, committed into the repo and executed within a migration. I see no better way for everyone to sync their working copies, along with the production DB, against new static data. Anyway, a good read!</description>
		<content:encoded><![CDATA[<p>Interesting and well thought out list. After about a solid year of Rails development, I think I may agree with all of your rules except for #13. A lot of the sites I work on deal with a static set of data, mostly geographic data &#8211; data that will never change. The data is prepared and generated once, then dumped into an SQL file, committed into the repo and executed within a migration. I see no better way for everyone to sync their working copies, along with the production DB, against new static data. Anyway, a good read!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton</title>
		<link>http://www.pathf.com/blogs/2008/12/rails-worst-practices-13-coding-nightmares-you-should-avoid/comment-page-1/#comment-4434</link>
		<dc:creator>Anton</dc:creator>
		<pubDate>Thu, 11 Dec 2008 11:12:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1314#comment-4434</guid>
		<description>Good post. I&#039;m glad I&#039;m not the only one who is guilty of breaking rule 13! I was starting to feel rather ashamed but the more I think about it the more I think there is a case for using it.

I think rule 13 is acceptable as long as you are using it on what I would term &quot;static data&quot;. That is data which is never changed by the end user (and certainly not data input by the end user) but is used by your application to perhaps populate a drop down box or something similar. 

I work in a University which is divided into faculties. Now these faculties are pretty constant but once in a while they change name slightly and I don&#039;t want to be unloading and reloading the faculties table with the new names because I&#039;ve got live data in the production system so instead I use migrations.

Now scenarios like the above I personally think are OK. However you raise a good point about using YML files and rake to populate the defaults and that&#039;s something I think I&#039;ll also do now so that anyone setting up a dev server from scratch can have the correct values in there without having to trawl through every migration.

In summary I think, if used correctly on static data, rule 13 is acceptable as long as you have the YML files and rake tasks to build the data from scratch without performing every migration. So the migrations are used purely for migrating existing databases where the data is referenced and cannot be deleted.</description>
		<content:encoded><![CDATA[<p>Good post. I&#8217;m glad I&#8217;m not the only one who is guilty of breaking rule 13! I was starting to feel rather ashamed but the more I think about it the more I think there is a case for using it.</p>
<p>I think rule 13 is acceptable as long as you are using it on what I would term &#8220;static data&#8221;. That is data which is never changed by the end user (and certainly not data input by the end user) but is used by your application to perhaps populate a drop down box or something similar. </p>
<p>I work in a University which is divided into faculties. Now these faculties are pretty constant but once in a while they change name slightly and I don&#8217;t want to be unloading and reloading the faculties table with the new names because I&#8217;ve got live data in the production system so instead I use migrations.</p>
<p>Now scenarios like the above I personally think are OK. However you raise a good point about using YML files and rake to populate the defaults and that&#8217;s something I think I&#8217;ll also do now so that anyone setting up a dev server from scratch can have the correct values in there without having to trawl through every migration.</p>
<p>In summary I think, if used correctly on static data, rule 13 is acceptable as long as you have the YML files and rake tasks to build the data from scratch without performing every migration. So the migrations are used purely for migrating existing databases where the data is referenced and cannot be deleted.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.320 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-03-09 21:55:21 -->
