This post originated from an RSS feed registered with Ruby Buzz
by Rick DeNatale.
Original Post: Conventions Uber Alles
Feed Title: Talk Like A Duck
Feed URL: http://talklikeaduck.denhaven2.com/articles.atom
Feed Description: Musings on Ruby, Rails, and other topics by an experienced object technologist.
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.