Conventions Uber Alles

Posted by Rick DeNatale Tue, 11 Sep 2007 23:24:00 GMT

One of the Rails mantras is “Convention over configuration.” Today I bumped up against that one in spades.

Being an agile sort of guy, I tend to make frequent small refactorings, ofen this involves renaming things. I’m working on a project which will involve talking to a remote legacy database. I’m building migrations to set up a
local development database which mirrors the schema of this database. I’d already generated a migration, and while
working on it decided that it needed to be renamed. So I changed it to something like “007_create_LEG_Frammis_table.rb” since the legacy table had the name (changed to protect the guilty) of LEG_Frammis.


I was shocked when I ran rake db:migrate only to find that rake blew up. Turning on the —trace option to rake
showed that it wasn’t even getting to my migration code. Instead some code in vendor/rails/activerecord/lib/active_record/migration.rb was getting an unexpected nil and trying to send the message first to it.


A quick look at the code didn’t reveal an obvious reason, so I broke out ruby-debug and ran rake under rdebug.


It turns out that rails REALLY expects migration names to match the regular expression /([0-9]+)([a-z0-9]*).rb/, those uppercase characters were the culprits.


Update


The patch, which Ben mentioned that he submitted in his comment, has been turned down because it would violate the assumption that round trips can be made between class names and file names.


Trackbacks

Use the following link to trackback from your own site:
http://talklikeaduck.denhaven2.com/trackbacks?article_id=462

Comments

  1. Ben about 13 hours later:

    Just submitted a patch for this, Rick. Hopefully it won’t bite anyone else :)